diff --git a/crates/metal2vulkan-conformance/known-gaps.tsv b/crates/metal2vulkan-conformance/known-gaps.tsv index ef40d566a..ccc7c03e2 100644 --- a/crates/metal2vulkan-conformance/known-gaps.tsv +++ b/crates/metal2vulkan-conformance/known-gaps.tsv @@ -96,15 +96,6 @@ attribute-stride-buffer * divergent case/nine-strides 7 elements differ (U32), t attribute-stride-plural-buffers * divergent case/nine-strides 7 elements differ (U32), the largest difference 16 Metal's `MTLAttributeStrideStatic` on a `[[stage_in]]` layout of `MTLBufferLayoutStrideDynamic` is not "read at stride 0"; it fetches the element at the bind offset for the FIRST element and hands every element past it ZERO. Measured on this M3 Max (macOS 27.0.1) from these cases' own committed recordings: a dynamic layout over a buffer holding `0x10 + e` at element `e`, eight threads stepping by thread position in x at rate 1, bound with the constant, answered `0x110` and then `0x100` seven times (the fixture writes the attribute plus `0x100`), while a bind at stride 0 answered `0x110` eight times -- so the two are different answers and Metal's validation stops neither. The same shape at a bind offset of 8 answered `0x112` and then `0x100` seven times, which says the bind offset still reaches the first element. Ours answers the stride-0 reading: `attribute_stride` (crates/metal2vulkan-runtime/src/argument_table.rs:377) maps the constant to `None`, `None` removes the index's entry from `ArgumentTable::attribute_strides`, and every reader of that map takes a missing entry as 0 -- the binder's push constant `PushField::StageInStride` (crates/metal2vulkan/src/lower/stage_io/stage_in.rs:179, whose own module note at line 28 says "as 0 for a buffer bound without one") and the reach check (crates/metal2vulkan-runtime/src/fetch_reach.rs:112). So the fetch walks elements at stride 0 and every thread reads element 0, which is a silently wrong answer rather than a refusal. The runtime already knows the real behaviour for ONE of the four setters: `ComputeCommandEncoder::set_bytes_with_stride` (crates/metal2vulkan-runtime/src/compute.rs:607) documents "an M4 read element 0 of the bytes and zeros past it" and refuses that combination `NotImplemented(KernelStageIn)` rather than emulating it -- this oracle shows the buffer forms behave the same way, so the note on the buffer forms (argument_table.rs:377 and compute.rs:509, "one bound without a stride reads at stride 0") is what is wrong, not the inline-bytes one. The fix belongs in the fetch, not in the table: `PushField::StageInStride` needs to be able to say "the constant was bound" apart from "stride 0" -- a sentinel value or a flag beside it -- and the pulled read in crates/metal2vulkan/src/lower/stage_io/stage_in.rs must then select the element at the bind offset where the element index is 0 and a zero of the attribute's form otherwise, which is the same predicate the inline-bytes form would need and would let that refusal be dropped too. It is deliberately NOT done here: this stream's target is the conformance suite, the change is to a published crate's shader lowering and its push-constant ABI (so it moves `SEMANTICS_VERSION` and every stage-in recording), and it needs release-mode evidence this stream has not taken. Scoped to every venue because the gap is in the push constant and the fetch's own arithmetic, before any device behaviour -- measured on this M3 Max alone, so every other venue is expected and unaudited. Open: for whoever takes the runtime's stage-in fetch. attribute-stride-buffer-offset * divergent case/nine-strides-and-two-offsets 14 elements differ (U32), the largest difference 18 Metal's `MTLAttributeStrideStatic` on a `[[stage_in]]` layout of `MTLBufferLayoutStrideDynamic` is not "read at stride 0"; it fetches the element at the bind offset for the FIRST element and hands every element past it ZERO. Measured on this M3 Max (macOS 27.0.1) from these cases' own committed recordings: a dynamic layout over a buffer holding `0x10 + e` at element `e`, eight threads stepping by thread position in x at rate 1, bound with the constant, answered `0x110` and then `0x100` seven times (the fixture writes the attribute plus `0x100`), while a bind at stride 0 answered `0x110` eight times -- so the two are different answers and Metal's validation stops neither. The same shape at a bind offset of 8 answered `0x112` and then `0x100` seven times, which says the bind offset still reaches the first element. Ours answers the stride-0 reading: `attribute_stride` (crates/metal2vulkan-runtime/src/argument_table.rs:377) maps the constant to `None`, `None` removes the index's entry from `ArgumentTable::attribute_strides`, and every reader of that map takes a missing entry as 0 -- the binder's push constant `PushField::StageInStride` (crates/metal2vulkan/src/lower/stage_io/stage_in.rs:179, whose own module note at line 28 says "as 0 for a buffer bound without one") and the reach check (crates/metal2vulkan-runtime/src/fetch_reach.rs:112). So the fetch walks elements at stride 0 and every thread reads element 0, which is a silently wrong answer rather than a refusal. The runtime already knows the real behaviour for ONE of the four setters: `ComputeCommandEncoder::set_bytes_with_stride` (crates/metal2vulkan-runtime/src/compute.rs:607) documents "an M4 read element 0 of the bytes and zeros past it" and refuses that combination `NotImplemented(KernelStageIn)` rather than emulating it -- this oracle shows the buffer forms behave the same way, so the note on the buffer forms (argument_table.rs:377 and compute.rs:509, "one bound without a stride reads at stride 0") is what is wrong, not the inline-bytes one. The fix belongs in the fetch, not in the table: `PushField::StageInStride` needs to be able to say "the constant was bound" apart from "stride 0" -- a sentinel value or a flag beside it -- and the pulled read in crates/metal2vulkan/src/lower/stage_io/stage_in.rs must then select the element at the bind offset where the element index is 0 and a zero of the attribute's form otherwise, which is the same predicate the inline-bytes form would need and would let that refusal be dropped too. It is deliberately NOT done here: this stream's target is the conformance suite, the change is to a published crate's shader lowering and its push-constant ABI (so it moves `SEMANTICS_VERSION` and every stage-in recording), and it needs release-mode evidence this stream has not taken. Scoped to every venue because the gap is in the push constant and the fetch's own arithmetic, before any device behaviour -- measured on this M3 Max alone, so every other venue is expected and unaudited. Open: for whoever takes the runtime's stage-in fetch. attribute-stride-inline-bytes * refused case/outcome/step/16/dispatchThreadgroups Err(Error::Bind("the bind state was refused: Unsupported(Unsupported { feature: KernelStageIn, needs: NotImplemented, location: None, symbol: None })")) The runtime refuses a kernel's `[[stage_in]]` fetch of INLINE BYTES bound with `MTLAttributeStrideStatic`, where plain Metal answers. Measured on this M3 Max (macOS 27.0.1) from this case's own committed recording: `setBytes:length:attributeStride:atIndex:` of the source bytes with the constant, under a dynamic-stride layout, answered `0x110` and then `0x100` seven times -- the element at the bind offset for the first element and zero past it -- and the command buffer completed. Ours refuses at the dispatch, `Unsupported(KernelStageIn)`, from the bind state; `ComputeCommandEncoder::set_bytes_with_stride` (crates/metal2vulkan-runtime/src/compute.rs:607) documents exactly that refusal and exactly that measured Metal answer, saying the fetch does not emulate it. By the owner's standing rule that what Metal allows we must allow, the refusal is a gap and not a settled difference. It is the same gap as the three `attribute-stride-*` divergences beside it and has the same fix -- teach `PushField::StageInStride` to say "the constant was bound" apart from "stride 0" and have the pulled read in crates/metal2vulkan/src/lower/stage_io/stage_in.rs select the first element and zeros past it -- after which this refusal can be dropped. The buffer forms answer the wrong value instead of refusing, which is the worse half of the same bug; this form at least fails visibly. Scoped to every venue because the refusal is in the encoder's bind state, before any Vulkan call. Open: for whoever takes the runtime's stage-in fetch. -half-texel-nans-r16f Apple M3 Max divergent case/words/nearest-sample 515 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-r16f Apple M3 Max divergent case/words/read-through-sample 515 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-r16f Apple M3 Max divergent case/words/read 515 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-rg16f Apple M3 Max divergent case/words/nearest-sample 1026 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-rg16f Apple M3 Max divergent case/words/read-through-sample 1026 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-rg16f Apple M3 Max divergent case/words/read 1026 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-rgba16f Apple M3 Max divergent case/words/nearest-sample 2045 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-rgba16f Apple M3 Max divergent case/words/read-through-sample 2045 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. -half-texel-nans-rgba16f Apple M3 Max divergent case/words/read 2045 elements differ (U16), the largest difference 33279 Metal's `texture2d` never widens, so a 16-bit float texel's NaN comes back as its own code -- sign, payload and signalling bit kept -- and ours answers the one positive quiet NaN `0x7e00` for every one of them. This M3's decode of such a texel into `f32` canonicalizes the NaN, so the code is gone before any conversion of ours sees it; no finite, zero, denormal or infinite texel differs anywhere, and the count is the same at every site. The translation reads every site through the device's decode, the GPU's native answer. Announced `device-nan-encoding`, whose definition in `pipeline/artifact.rs` says validation derives no tolerance from it, so the rows stay divergent. format-footprints-astc-4x2-and-8x4 * refused case/MTLPixelFormatASTC_4x2_sRGB/Type2D/64x64x1/levels-1/samples-1/slices-1/usage-0x1/shared/makes-texture Err(Error::Unsupported("unsupported: Unsupported { feature: Format, needs: NotImplemented, location: None, symbol: Some(\"MTLPixelFormatASTC_4x2_sRGB\") }")) The runtime answers Metal's heap footprint for ASTC's 4x2 and 8x4 footprints, which is arithmetic over a descriptor, but holds no image of any of them, so `newTextureWithDescriptor:` is refused `Unsupported(Format, NotImplemented)` out of the translator's format table (crates/metal2vulkan/src/metal/format/mod.rs, the `formats_named_not_held!` and `astc_without_a_vulkan_block!` patterns, whose `repr` is `NotImplemented`; the refusal reaches this site through `image_error` in crates/metal2vulkan-runtime/src/texture.rs). Measured on an Apple M3 Max under macOS 27.0.1, plain Metal, in a throwaway process forked per (format, texture type): Metal answers a size and an alignment for every descriptor of this case, makes a texture of every format in every texture type bar the ones the case's own module records, and takes a host round trip through each. The whole of Metal's answer is in this case's recording, which is what an implementation will be held to. The case STOPS at this first refusal by design: the runtime holds no image of any of the 33 formats of the family, so recording a refusal per site and going on would print some 2900 `Refused` rows and need a ledger row for each. So this one row stands for the family, and the open work -- an image for each format -- is on the orchestrator's todo list with the measurements. Scoped `*` and not to a venue: the refusal is decided by the format table before any device is consulted, so no device can change it; verified on MoltenVK over this M3 Max (2026-10-25), unverified elsewhere by execution. format-footprints-plain-stragglers * refused case/MTLPixelFormatARGB8Unorm_sRGB/Type2D/64x64x1/levels-1/samples-1/slices-1/usage-0x1/shared/makes-texture Err(Error::Unsupported("unsupported: Unsupported { feature: Format, needs: NotImplemented, location: None, symbol: Some(\"MTLPixelFormatARGB8Unorm_sRGB\") }")) Plain Metal makes a texture of `ARGB8Unorm_sRGB` in all eight non-multisample texture types and takes a host `replaceRegion:`/`getBytes:` round trip through each (an Apple M3 Max under macOS 27.0.1, in a throwaway process forked per (format, texture type); the whole of its answer is in this case's recording). The runtime refuses `newTextureWithDescriptor:` `Unsupported(Format, NotImplemented)` out of the translator's format table (crates/metal2vulkan/src/metal/format/mod.rs, the `formats_named_not_held!` pattern, whose `repr` is `NotImplemented`; the refusal reaches this site through `image_error` in crates/metal2vulkan-runtime/src/texture.rs). The cause is NOT that the bytes have no Vulkan format: they are `ARGB8Unorm`'s (alpha in byte 0, then red, green and blue), which this crate holds in `R8G8B8A8_UNORM` read through a rotating view, and `fill_value.rs` already states this format's own layout as a linear alpha byte and three sRGB bytes. It is that no Vulkan format applies the sRGB transfer function to the three channels Metal's does: every Vulkan `_SRGB` format encodes the word's low three components and leaves the fourth linear, so the function would land on Metal's alpha and miss Metal's blue. A view's component mapping cannot move it, because format conversion runs before the component swizzle, so `R8G8B8A8_SRGB` under `ARGB8Unorm`'s rotation would read Metal's alpha sRGB-decoded and Metal's blue linear -- two channels of four wrong, which is not a near-equivalent a precision note could carry. The exact form is the one a device that cannot sample an 8-bit sRGB format already takes: hold the codes in a UNORM image (here `ARGB8Unorm`'s `R8G8B8A8_UNORM` image through its rotating view) and decode them in the shader through Metal's twelve-bit table (`metal::format::srgb_raw_twin`, `metal::texel_format::srgb_twin_on`, `RuntimeFact::SrgbTexture`, `lower::arith::srgb`), here as the only read of the format on every device, since no view of this image decodes it, so a clear, a blit and a colour attachment of it must take the same route. That is not built. Open: translator and runtime work, in metal2vulkan's format table and the UNORM twin's format map with the runtime's image plan and binder. Its sibling straggler `BGRA4Unorm` is held, which is why the case reaches this format. Scoped `*` and not to a venue: the refusal is decided by the format table before any device is consulted, so no device can change it; verified on MoltenVK over this M3 Max (2026-10-25), unverified elsewhere by execution. format-footprints-one-plane-ycbcr * refused case/MTLPixelFormatYCBCR8_422_1P/Type2D/64x64x1/levels-1/samples-1/slices-1/usage-0x1/shared/makes-texture Err(Error::Unsupported("unsupported: Unsupported { feature: Format, needs: NotImplemented, location: None, symbol: Some(\"MTLPixelFormatYCBCR8_422_1P\") }")) The runtime answers Metal's heap footprint for Apple's nine one-plane YCbCr formats, which is arithmetic over a descriptor, but holds no image of any of them, so `newTextureWithDescriptor:` is refused `Unsupported(Format, NotImplemented)` out of the translator's format table (crates/metal2vulkan/src/metal/format/mod.rs, the `formats_named_not_held!` and `astc_without_a_vulkan_block!` patterns, whose `repr` is `NotImplemented`; the refusal reaches this site through `image_error` in crates/metal2vulkan-runtime/src/texture.rs). Measured on an Apple M3 Max under macOS 27.0.1, plain Metal, in a throwaway process forked per (format, texture type): Metal answers a size and an alignment for every descriptor of this case, makes a texture of every format in every texture type bar the ones the case's own module records, and takes a host round trip through each. The whole of Metal's answer is in this case's recording, which is what an implementation will be held to. The case STOPS at this first refusal by design: the runtime holds no image of any of the 33 formats of the family, so recording a refusal per site and going on would print some 2900 `Refused` rows and need a ledger row for each. So this one row stands for the family, and the open work -- an image for each format -- is on the orchestrator's todo list with the measurements. Scoped `*` and not to a venue: the refusal is decided by the format table before any device is consulted, so no device can change it; verified on MoltenVK over this M3 Max (2026-10-25), unverified elsewhere by execution. @@ -427,35 +418,6 @@ attribute-format-fetches llvmpipe divergent case/MTLAttributeFormatHalf/attribut attribute-format-fetches llvmpipe divergent case/MTLAttributeFormatHalf2/attribute0/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 2147491840 A NaN of a narrow float attribute (`half`, or a small float of `FloatRG11B10`) fetched by fixed-function vertex input: Metal answers its canonical `0x7FC00000`, and ours keeps the device's widening of the NaN, its payload included (0x7FC02000, or 0x7FFE0000 for the small float, at the first differing element). Under the native-arithmetic contract the device's widening is the answer: `device-nan-encoding` records a fixed-function attribute of a float format narrower than 32 bits, whose NaN Metal widens to `0x7FC00000` and the device's widening need not, and validation derives no tolerance from it. Open: nothing. attribute-format-fetches llvmpipe divergent case/MTLAttributeFormatHalf3/attribute0/MTLAttributeFormatHalf3 6 elements differ (U32), the largest difference 2147491840 A NaN of a narrow float attribute (`half`, or a small float of `FloatRG11B10`) fetched by fixed-function vertex input: Metal answers its canonical `0x7FC00000`, and ours keeps the device's widening of the NaN, its payload included (0x7FC02000, or 0x7FFE0000 for the small float, at the first differing element). Under the native-arithmetic contract the device's widening is the answer: `device-nan-encoding` records a fixed-function attribute of a float format narrower than 32 bits, whose NaN Metal widens to `0x7FC00000` and the device's widening need not, and validation derives no tolerance from it. Open: nothing. attribute-format-fetches llvmpipe divergent case/MTLAttributeFormatHalf4/attribute0/MTLAttributeFormatHalf4 8 elements differ (U32), the largest difference 2147491840 A NaN of a narrow float attribute (`half`, or a small float of `FloatRG11B10`) fetched by fixed-function vertex input: Metal answers its canonical `0x7FC00000`, and ours keeps the device's widening of the NaN, its payload included (0x7FC02000, or 0x7FFE0000 for the small float, at the first differing element). Under the native-arithmetic contract the device's widening is the answer: `device-nan-encoding` records a fixed-function attribute of a float format narrower than 32 bits, whose NaN Metal widens to `0x7FC00000` and the device's widening need not, and validation derives no tolerance from it. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatChar2Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatChar3Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatChar4Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatCharNormalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatFloat/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatFloat2/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatFloat3/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatFloat4/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatFloatRG11B10/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatFloatRGB9E5/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatHalf/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatHalf2/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatHalf3/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatHalf4/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatInt1010102Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatShort2Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatShort3Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatShort4Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatShortNormalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar2Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar3Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar4Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar4Normalized_BGRA/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUCharNormalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUInt1010102Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUShort2Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUShort3Normalized/attribute3/MTLAttributeFormatHalf 2 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUShort4Normalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. -attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUShortNormalized/attribute3/MTLAttributeFormatHalf2 4 elements differ (U32), the largest difference 32769 A `half` attribute's NaN fetched through `[[stage_in]]` into the fixture's `half2` and reinterpreted (`as_type`): Metal moves the attribute's own bits, and ours answers the canonical quiet NaN `0x7E00` for each of the sweep's two `half` NaNs, 0x7E01 and 0xFE01 (the site's largest difference, 32769, is the negative one's sign and payload); every other code of the site is Metal's. The module reads the `half` from its bits through the device's widening, which on this M3 makes a NaN the canonical one, and narrows the widened value back for the reinterpretation: `native-nan-encoding` records every module that reads a `half` from its bits, whose NaN widens to a NaN of the device's bits and may leave with them, and validation derives no tolerance from it. lavapipe's conversions keep the bits there. Open: nothing. attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar2Normalized/attribute0/MTLAttributeFormatUChar2Normalized 8 elements differ (U32), the largest difference 1 Metal converts a normalized attribute field as `c / (2^b - 1)`, correctly rounded, and a kernel's `[[stage_in]]` attribute is always the shader's own fetch, whose decode is the device's product of the code and its maximum's reciprocal, `float(c) * float(1 / 255)`, one ULP high at some codes: 127/255 is 0x3EFEFEFF in Metal's answer, the nearest `float`, and 0x3EFEFF00 in ours, the next `float` up (one ULP, a difference of 1 in the word). Under the native-arithmetic contract the device's product is the answer: the kernel records `device-vertex-conversion` for a normalized stage-in attribute, and its recorded bound names exactly this, 126 of the 256 8-bit unsigned codes one ulp high. Validation derives no tolerance from it. Open: nothing. attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar3Normalized/attribute0/MTLAttributeFormatUChar3Normalized 12 elements differ (U32), the largest difference 1 Metal converts a normalized attribute field as `c / (2^b - 1)`, correctly rounded, and a kernel's `[[stage_in]]` attribute is always the shader's own fetch, whose decode is the device's product of the code and its maximum's reciprocal, `float(c) * float(1 / 255)`, one ULP high at some codes: 127/255 is 0x3EFEFEFF in Metal's answer, the nearest `float`, and 0x3EFEFF00 in ours, the next `float` up (one ULP, a difference of 1 in the word). Under the native-arithmetic contract the device's product is the answer: the kernel records `device-vertex-conversion` for a normalized stage-in attribute, and its recorded bound names exactly this, 126 of the 256 8-bit unsigned codes one ulp high. Validation derives no tolerance from it. Open: nothing. attribute-format-fetches Apple M3 Max divergent case/MTLAttributeFormatUChar4Normalized/attribute0/MTLAttributeFormatUChar4Normalized 16 elements differ (U32), the largest difference 1 Metal converts a normalized attribute field as `c / (2^b - 1)`, correctly rounded, and a kernel's `[[stage_in]]` attribute is always the shader's own fetch, whose decode is the device's product of the code and its maximum's reciprocal, `float(c) * float(1 / 255)`, one ULP high at some codes: 127/255 is 0x3EFEFEFF in Metal's answer, the nearest `float`, and 0x3EFEFF00 in ours, the next `float` up (one ULP, a difference of 1 in the word). Under the native-arithmetic contract the device's product is the answer: the kernel records `device-vertex-conversion` for a normalized stage-in attribute, and its recorded bound names exactly this, 126 of the 256 8-bit unsigned codes one ulp high. Validation derives no tolerance from it. Open: nothing. @@ -729,8 +691,6 @@ integer-vertex-attributes llvmpipe divergent case/int_attribute_to_half4/UShort4 integer-vertex-attributes llvmpipe divergent case/int_attribute_to_half4/UShort4/per-vertex/rows 20 elements differ (F32), the largest difference inf An integer attribute the function reads as `half`: Metal rounds the value to `half` (32767 to 32768, 2049 to 2048, and a value past the range to infinity), and ours keeps the integer's `float` value unrounded, finite past the range, so a site's largest difference may be infinite. `native-half-conversion`'s recorded bound states it: lavapipe drops the conversion, the result is the `float` itself, and a value past the range stays finite. Validation derives no tolerance from it. Open: nothing. math-frexp-ilogb-half llvmpipe divergent case/output/frexp-mantissa 1 element differs (U32): Metal 31745 (0x7c01), ours 32257 (0x7e01) `frexp` of a signalling `half` NaN: Metal's mantissa is the operand's own bits (0x7C01), and ours is the device's quiet NaN of the same payload (0x7E01). `native-nan-encoding`'s recorded bound covers it: where Metal answers an operand's bits, the device answers a NaN whose bits are its own. Validation derives no tolerance from it. Open: nothing. math-frexp-ilogb-half llvmpipe divergent case/output/frexp4-mantissa-lane1 1 element differs (U32): Metal 31745 (0x7c01), ours 32257 (0x7e01) `frexp` of a signalling `half` NaN: Metal's mantissa is the operand's own bits (0x7C01), and ours is the device's quiet NaN of the same payload (0x7E01). `native-nan-encoding`'s recorded bound covers it: where Metal answers an operand's bits, the device answers a NaN whose bits are its own. Validation derives no tolerance from it. Open: nothing. -math-frexp-ilogb-half Apple M3 Max divergent case/output/frexp-mantissa 3 elements differ (U32), the largest difference 32853 `frexp` of a `half` NaN, each of the sweep's three (a quiet one with a payload, a negative one, a signalling one): Metal's mantissa is the operand's own bits (0x7E01, 0xFE55, 0x7C01), and ours is the canonical quiet NaN 0x7E00 for each (the site's largest difference, 32853, is the negative one's sign and payload). `native-nan-encoding`'s recorded bound covers it: where Metal answers an operand's bits, the device answers a NaN whose sign and payload are its own, here the canonical one. Validation derives no tolerance from it. Open: nothing. -math-frexp-ilogb-half Apple M3 Max divergent case/output/frexp4-mantissa-lane1 3 elements differ (U32), the largest difference 32853 `frexp` of a `half` NaN, each of the sweep's three (a quiet one with a payload, a negative one, a signalling one): Metal's mantissa is the operand's own bits (0x7E01, 0xFE55, 0x7C01), and ours is the canonical quiet NaN 0x7E00 for each (the site's largest difference, 32853, is the negative one's sign and payload). `native-nan-encoding`'s recorded bound covers it: where Metal answers an operand's bits, the device answers a NaN whose sign and payload are its own, here the canonical one. Validation derives no tolerance from it. Open: nothing. nearest-sample-positions llvmpipe divergent case/mirrored/sampled 43 elements differ (U32), the largest difference 131072 A nearest sample at coordinates on texel boundaries under repeat and mirrored repeat: where the elements differ, ours reads the neighbouring texel (Metal 88 against our 87 or 89). `device-sampling` records that a nearest sample within the device's sub-texel precision of a texel boundary may read the neighbouring texel; its probe found none on lavapipe at its coordinates, which do not sit on boundaries as this case's do. Validation derives no tolerance from it. Open: nothing. nearest-sample-positions llvmpipe divergent case/repeat/sampled 36 elements differ (U32), the largest difference 1572864 A nearest sample at coordinates on texel boundaries under repeat and mirrored repeat: where the elements differ, ours reads the neighbouring texel (Metal 88 against our 87 or 89). `device-sampling` records that a nearest sample within the device's sub-texel precision of a texel boundary may read the neighbouring texel; its probe found none on lavapipe at its coordinates, which do not sit on boundaries as this case's do. Validation derives no tolerance from it. Open: nothing. norm-storage-codes-rgb10a2unorm llvmpipe divergent case/hsw_buffer/texels 505 elements differ (U32), the largest difference 1074791425 A `float` the function writes to a normalized storage texture at a tie between two codes: Metal stores the exact product rounded with a tie away from zero, and this device rounds the tie to even, so each tie channel is a code apart (the report compares whole words, so its difference adds a word's channels together: Metal 0x01010101 against our 0x00000000 is four channels a code apart). Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records exactly this for a storage write the device converts, and validation derives no tolerance from it. Open: nothing. diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 77ddb6476..3c82303fd 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -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 = 1919; +pub const SEMANTICS_VERSION: u32 = 1920; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another diff --git a/crates/metal2vulkan/src/lower/arith/narrow.rs b/crates/metal2vulkan/src/lower/arith/narrow.rs index 989425133..a6fdb79da 100644 --- a/crates/metal2vulkan/src/lower/arith/narrow.rs +++ b/crates/metal2vulkan/src/lower/arith/narrow.rs @@ -32,10 +32,13 @@ //! ([`device_from_bits`]), else `GLSL.std.450 UnpackHalf2x16` of the bits as the low half of a //! word ([`unpacked_from_bits`]), which needs no 16-bit type: the device's value of every `half` //! but a NaN's bits and, on a device that may flush 16-bit denormals, a denormal, each recorded -//! ([`widens_bits`]). Every other crossing is exact: [`to_bits`] and a `bfloat`'s move between a -//! value and its format bits with integer sequences and, for a half denormal, one exact scaling by -//! `2^24` of a normal `f32` to an integer (denormals, infinities, and NaN payloads included); an -//! integer converts to `half` through `f32` without +//! ([`widens_bits`]). A `half`'s bits from its value, where they are not known from the bits it +//! was read from, are the device's narrowing of it on every profile ([`to_bits`]): its conversion +//! to a 16-bit float read as a word where the module can hold one ([`converted_bits`]), else +//! `GLSL.std.450 PackHalf2x16` ([`packed_bits`]), the same two notes recorded +//! ([`encodes_bits`]). Every other crossing is exact: a `bfloat`'s move between a value and its +//! format bits with integer shifts (NaN payloads included); an integer converts to `half` through +//! `f32` without //! double rounding (any integer the `f32` step rounds is at least `2^24`, far above the largest //! half) and rounds by integer arithmetic, not `OpQuantizeToF16`, around a driver's defect //! ([`round_integer`]), an integer converts to `bfloat` through a round-to-odd `f32` @@ -160,8 +163,8 @@ pub fn native_rounding(form: QuantizeForm) -> Option { /// instruction computing `x`: Metal's compiler then rounds toward zero (`a1_half_tanh_regimes`, /// case 27353187: 1,204 of its 16,384 halves one ulp toward zero on MoltenVK). NVIDIA's compiler /// (RTX 3090) drops the pair, and so does lavapipe's where measured, so there the value is not -/// rounded at all (the note's stated bound), and the store's bits saturate what passes `half`'s -/// range ([`f32_bits_to_half_bits`]). +/// rounded at all (the note's stated bound), and the store's conversion to bits rounds it +/// ([`converted_bits`]). fn converted(fb: &mut FunctionBuilder<'_>, wide: Form, x: Value) -> BResult { let e = fb.module().ty(Type::Float { width: 16 })?; let h = match wide.lanes { @@ -447,22 +450,25 @@ fn bf16_round_bits(fb: &mut FunctionBuilder<'_>, u: Form, b: Value) -> BResult u32 { match f.float_fmt() { - Some(FloatFmt::Half) => 136, + Some(FloatFmt::Half) => 48, Some(FloatFmt::BFloat) => 24, _ => 0, } } -/// The format bits (zero-extended in `u32` lanes) of narrow value `x` of form `f`. Exact for -/// every value of the format, including denormals, infinities, and NaN payloads (a NaN whose -/// payload does not survive is quieted, never turned into an infinity). +/// The format bits (zero-extended in `u32` lanes) of narrow value `x` of form `f`. A `bfloat`'s +/// are exact for every value of the format. A `half`'s are the device's narrowing of the value +/// ([`encode`]): exact for every `half` value but a NaN's bits and, on a device that may flush +/// 16-bit denormals, a denormal, each recorded ([`encodes_bits`]). /// -/// Bits already known are reused: see `known_bits`; and a lane extract's bits are taken from its -/// vector's when those are known. Each is exactly what the sequence below computes from the value, -/// so the result does not depend on which is taken. +/// Bits already known are reused: see `known_bits`, so a `half` loaded and stored unchanged keeps +/// its bits, a NaN's payload included; and a lane extract's bits are taken from its vector's when +/// those are known. Each is the value's bits, so the result does not depend on which is taken but +/// for a NaN's, which the device's narrowing may encode otherwise. pub fn to_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult { let Some(fmt) = narrow_fmt(f) else { return encode(fb, f, x); @@ -503,11 +509,11 @@ pub fn to_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult, fmt: NarrowFmt, @@ -546,7 +552,7 @@ fn clean( } /// The most lane inserts [`inserted_bits`] repeats on bits: a bound on its work (a longer chain -/// runs the sequence). +/// is encoded, [`encode`]). const MAX_INSERTS: usize = 16; /// Where a lane insert's bits come from. @@ -742,24 +748,223 @@ fn vector_lanes(fb: &mut FunctionBuilder<'_>, v: Value) -> BResult> { }) } -/// The format bits of narrow value `x` of form `f`, computed by the exact sequence. +/// The format bits of narrow value `x` of form `f`, where no known bits stand: a `bfloat`'s its +/// `f32` bits moved down, exact; a `half`'s the device's narrowing of the value, its conversion to +/// a 16-bit float where the module can hold one (every [`QuantizeForm`] but +/// [`QuantizeForm::Device`], [`converted_bits`]), else `GLSL.std.450 PackHalf2x16` +/// ([`packed_bits`]). fn encode(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult { - let u = u32_form(f); - let ut = ty(fb, u)?; - let b = fb.convert(ConvOp::Bitcast, x, ut)?; - match f.held { - Held::Float(FloatFmt::BFloat) => { + match (f.held, fb.module().quantize_form()) { + (Held::Float(FloatFmt::BFloat), _) => { + let u = u32_form(f); + let ut = ty(fb, u)?; + let b = fb.convert(ConvOp::Bitcast, x, ut)?; let k16 = splat(fb, u, 16)?; bin(fb, BinOp::ShiftRightLogical, b, k16) } - _ => f32_bits_to_half_bits(fb, u, b), + (_, QuantizeForm::Device) => packed_bits(fb, f, x), + (_, QuantizeForm::Converted | QuantizeForm::Controlled) => converted_bits(fb, f, x), } } +/// The `half` bits of `x` (`f32` lanes of form `f`), zero-extended in `u32` lanes, by the device's +/// conversion to 16 bits: the lanes converted at once, one `OpFConvert` (decorated `NoContraction` +/// under the float controls, as [`controlled`]'s), and each beside a 16-bit zero read as a word +/// (`OpBitcast` maps the lower-numbered component to a word's lower-ordered bits), two lanes at a +/// time as four. Three instructions for one or two lanes, six for three or four. +/// +/// Every `half` value converts to its own bits, by the Vulkan spec ("Precision and Operation of +/// SPIR-V Instructions": a conversion is "Correctly rounded"), but a NaN, whose bits are the +/// device's (the SPIR-V spec's `SignedZeroInfNanPreserve`: "Bit patterns for NaNs might not be +/// preserved"), where Metal moves a `half` NaN with its bits, and a denormal, which the device may +/// flush to the zero of its sign without `DenormPreserve` for 16 bits: kept under the float +/// controls ([`QuantizeForm::Controlled`], [`controlled_modes`]), measured kept on MoltenVK +/// (`DriverDeviation::MetalHalfArithmetic`, whose measurement narrows every `half`), and elsewhere +/// within `PrecisionNote::NativeHalfConversion`'s bound; the module records +/// `PrecisionNote::NativeNanEncoding` ([`encodes_bits`]). A value that is no `half` value (under +/// native half rounding the device's compiler may fold [`converted`]'s pair and hand `x` on +/// unrounded, as NVIDIA's and lavapipe's do) takes the device's rounding, within +/// `PrecisionNote::NativeHalfConversion`'s bound, which that module records. +fn converted_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult { + let e = fb.module().ty(Type::Float { width: 16 })?; + let halves = + |fb: &mut FunctionBuilder<'_>, len: u8| fb.module().ty(Type::Vector { elem: e, len }); + let words = |fb: &mut FunctionBuilder<'_>, lanes: u8| ty(fb, u32_form(Form { lanes, ..f })); + let narrow = |fb: &mut FunctionBuilder<'_>, to| match fb.module().quantize_form() { + QuantizeForm::Controlled => fb.convert_no_contraction(x, to), + _ => fb.convert(ConvOp::FConvert, x, to), + }; + if f.lanes <= 1 { + let h = narrow(fb, e)?; + let k = fb.module().constant(Constant::Null { ty: e })?; + let z = fb.module().const_value(k)?; + let pair = halves(fb, 2)?; + let p = fb.composite_construct(pair, &[h, z])?; + let w = words(fb, 1)?; + return fb.convert(ConvOp::Bitcast, p, w); + } + let n = u32::from(f.lanes); + let hv = halves(fb, f.lanes)?; + let h = narrow(fb, hv)?; + let pair = halves(fb, 2)?; + let k = fb.module().constant(Constant::Null { ty: pair })?; + let zeros = fb.module().const_value(k)?; + // At most two parts: a vector holds at most four lanes. Index `n` is a zero. + let mut parts = Vec::with_capacity(2); + let mut at = 0u32; + while at < n { + let part = if n - at >= 2 { + let q = fb.vector_shuffle(h, zeros, &[at, n, at + 1, n])?; + let w = words(fb, 2)?; + at += 2; + fb.convert(ConvOp::Bitcast, q, w)? + } else { + let p = fb.vector_shuffle(h, zeros, &[at, n])?; + let w = words(fb, 1)?; + at += 1; + fb.convert(ConvOp::Bitcast, p, w)? + }; + parts.push(part); + } + match parts.as_slice() { + [one] => Ok(*one), + _ => { + let ut = ty(fb, u32_form(f))?; + fb.composite_construct(ut, &parts) + } + } +} + +/// The `half` bits of `x` (`f32` lanes of form `f`), zero-extended in `u32` lanes, by +/// `GLSL.std.450 PackHalf2x16` ([`QuantizeForm::Device`], a profile without `shaderFloat16`): each +/// lane packed beside a zero, so a word's low 16 bits are the lane's `half` and its high 16 bits +/// the zero's. Two instructions a lane, and a vector's construct. +/// +/// It needs no 16-bit type: the instruction is core to every Vulkan device. Vulkan gives it no +/// precision of its own ("implementation-defined"); every `half` value is an `f32`, and the +/// device's narrowing is its answer: a NaN packs to a NaN whose bits are the device's, where Metal +/// moves a `half` NaN with its bits, and a denormal may be flushed to the zero of its sign without +/// `DenormPreserve` for 16 bits, which such a module does not declare. The module records +/// `PrecisionNote::NativeNanEncoding` and `PrecisionNote::NativeHalfConversion` +/// ([`encodes_bits`]). +fn packed_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult { + let wide = |lanes: u8| Form { + held: Held::Float(FloatFmt::F32), + lanes, + }; + if f.lanes <= 1 { + let z = fsplat(fb, wide(1), 0.0)?; + let pair = ty(fb, wide(2))?; + let p = fb.composite_construct(pair, &[x, z])?; + return fb.glsl(GlslOp::PackHalf2x16, &[p]); + } + let n = u32::from(f.lanes); + // Index `n` is a zero. + let zeros = fsplat(fb, wide(2), 0.0)?; + let mut words = Vec::with_capacity(usize::from(f.lanes)); + for i in 0..n { + let p = fb.vector_shuffle(x, zeros, &[i, n])?; + words.push(fb.glsl(GlslOp::PackHalf2x16, &[p])?); + } + let ut = ty(fb, u32_form(f))?; + fb.composite_construct(ut, &words) +} + +/// Whether module `m` narrows a `half` to its bits by the device ([`to_bits`]): a +/// `GLSL.std.450 PackHalf2x16` ([`packed_bits`], in [`QuantizeForm::Device`]), or an `OpBitcast` +/// to integers of an `OpFConvert` from 32 to 16 bits, or of a construct or shuffle of one +/// ([`converted_bits`]). It moves a `half` between its value and its bits as [`widens_bits`]'s +/// widening does the other way, with the same notes: the module records +/// `PrecisionNote::NativeNanEncoding` (a NaN's bits the device's); under the float controls +/// ([`QuantizeForm::Controlled`]) its entry declares [`controlled_modes`], and elsewhere its +/// denormals are the measured fact's (`DriverDeviation::MetalHalfArithmetic`) or the device's +/// (`PrecisionNote::NativeHalfConversion`). At most three passes over the instructions, with two +/// bits per value of the module charged to `meter` while they run. +pub fn encodes_bits(m: &TypedModule, meter: &mut Meter) -> Result { + let packs = m.blocks().iter().flat_map(|b| &b.insts).any(|n| { + matches!( + n.inst, + Inst::Glsl { + op: GlslOp::PackHalf2x16, + .. + } + ) + }); + if packs { + return Ok(true); + } + // The width of `v`'s float lanes, if it is a float or a vector of floats; integers are `0`. + let width = |v: Value| -> Option { + let ty = m.value(v).ok()?.ty; + let ty = match m.types().get(ty).ok()? { + Type::Vector { elem, .. } => *elem, + _ => ty, + }; + match m.types().get(ty).ok()? { + Type::Float { width } => Some(*width), + Type::Int { .. } => Some(0), + _ => None, + } + }; + let insts = || m.blocks().iter().flat_map(|b| &b.insts); + let words = m.values().len().div_ceil(64); + meter.charge(16 * words)?; + let mut narrowed = vec![0u64; words]; + let mut gathered = vec![0u64; words]; + let set = |bits: &mut [u64], v: Value| { + if let Some(w) = bits.get_mut(v.index() / 64) { + *w |= 1 << (v.index() % 64); + } + }; + let has = |bits: &[u64], v: Value| { + bits.get(v.index() / 64) + .is_some_and(|w| w & (1 << (v.index() % 64)) != 0) + }; + for n in insts() { + if let ( + Inst::Convert { + op: ConvOp::FConvert, + a, + .. + }, + Some(r), + ) = (&n.inst, n.result) + { + if width(*a) == Some(32) && width(r) == Some(16) { + set(&mut narrowed, r); + } + } + } + for n in insts() { + let taken = match &n.inst { + Inst::CompositeConstruct { parts } => parts.iter().any(|p| has(&narrowed, *p)), + Inst::VectorShuffle { a, b, .. } => has(&narrowed, *a) || has(&narrowed, *b), + _ => false, + }; + if let (true, Some(r)) = (taken, n.result) { + set(&mut gathered, r); + } + } + let found = insts().any(|n| match (&n.inst, n.result) { + ( + Inst::Convert { + op: ConvOp::Bitcast, + a, + .. + }, + Some(r), + ) => (has(&narrowed, *a) || has(&gathered, *a)) && width(r) == Some(0), + _ => false, + }); + drop((narrowed, gathered)); + meter.release(16 * words); + Ok(found) +} + /// The format bits of `x` (form `f`) when `x` is a plain constant every lane of which is a -/// value of the format, computed at translation time by [`half_bits_of_f32`], the transliteration -/// of the device sequence, and checked by [`f32_of_half_bits`]: `None` for anything else (the -/// device sequence then runs). A `null` is zero bits. +/// value of the format, computed at translation time by [`half_bits_of_f32`] and checked by +/// [`f32_of_half_bits`]: `None` for anything else (the device's narrowing then runs, [`encode`]). +/// A `null` is zero bits. pub fn constant_bits(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult> { match constant_lanes(fb, f, x)? { Some(k) => materialize(fb, f, &k).map(Some), @@ -823,8 +1028,9 @@ fn materialize(fb: &mut FunctionBuilder<'_>, f: Form, lanes: &[u64]) -> BResult< fb.module().const_value(k) } -/// The host transliteration of `f32_bits_to_half_bits` on one lane: the half bits of the -/// `f32` with bits `b` (exact when `b` is a half value). +/// The half bits of the `f32` with bits `b`, on the host, exact when `b` is a half value (a NaN's +/// payload moved down under the all-ones exponent, quieted where its top bits are all zero): the +/// bits [`constant_bits`] folds a constant to. pub fn half_bits_of_f32(b: u32) -> u32 { let a = b & 0x7FFF_FFFF; let sign = (b >> 16) & 0x8000; @@ -862,70 +1068,6 @@ pub fn f32_of_half_bits(h: u32) -> u32 { ((h & 0x8000) << 16) | r } -/// `f32` bits `b` of a half value to its half bits: the magnitude `a` rebiased by `112 << 10` after -/// dropping the 13 bits a half does not have; an infinity or NaN rebiased by `224 << 10`, to the -/// half's all-ones exponent with the payload's top bits (a NaN whose top bits are all zero is -/// quieted, never made infinite); a value below the smallest normal half (a half denormal or zero) -/// is `|x| · 2^24` converted to an integer, which is exact: `|x|` is a multiple of `2^-24` at least -/// `2^-24` (a normal `f32`, so no device flushes it) or zero, and the product is an integer below -/// `2^10`. -/// -/// Under native half rounding ([`crate::spirv::builder::ModuleBuilder::native_half`]) the value -/// need not be a half value: the device's compiler may fold [`converted`]'s conversion pair, which -/// is the device's own, and hand over `x` unrounded (NVIDIA and lavapipe do). A finite -/// magnitude from `65536` up then rebiases past the half's exponent, to a NaN's code or beyond 16 -/// bits, whose bit 17 a store's pairing carries into the next lane; so there the finite code is -/// capped at infinity's, `0x7C00`. Every other value takes the truncation, within the native -/// conversion's bound (`NativeHalfConversion`: one ulp, and 65504 where Metal answers infinity). -fn f32_bits_to_half_bits(fb: &mut FunctionBuilder<'_>, u: Form, b: Value) -> BResult { - let c = |fb: &mut FunctionBuilder<'_>, k: u64| splat(fb, u, k); - let abs_mask = c(fb, 0x7FFF_FFFF)?; - let a = bin(fb, BinOp::BitwiseAnd, b, abs_mask)?; - let k16 = c(fb, 16)?; - let sign = bin(fb, BinOp::ShiftRightLogical, b, k16)?; - let sm = c(fb, 0x8000)?; - let sign = bin(fb, BinOp::BitwiseAnd, sign, sm)?; - let k13 = c(fb, 13)?; - let t = bin(fb, BinOp::ShiftRightLogical, a, k13)?; - let inf = c(fb, 0x7F80_0000)?; - let is_special = bin(fb, BinOp::UGreaterThanEqual, a, inf)?; - let (special_bias, bias) = (c(fb, 224 << 10)?, c(fb, 112 << 10)?); - let bias = fb.select(is_special, special_bias, bias)?; - let normal = bin(fb, BinOp::ISub, t, bias)?; - // The cap is the bias less `0x14400`: `0x7C00` for a finite lane, `0x23C00` for an infinity - // or NaN, whose code (at most `0x7FFF`) it leaves alone. - let normal = match fb.module().native_half() { - true => { - let less = c(fb, 0x14400)?; - let cap = bin(fb, BinOp::ISub, bias, less)?; - fb.glsl(GlslOp::UMin, &[normal, cap])? - } - false => normal, - }; - // A NaN whose payload lies below the half's bits: `a` in `(0x7F80_0000, 0x7F80_2000)`. - let first_nan = c(fb, 0x7F80_0001)?; - let low = bin(fb, BinOp::ISub, a, first_nan)?; - let span = c(fb, 0x1FFF)?; - let lost = bin(fb, BinOp::ULessThan, low, span)?; - let quiet = c(fb, 0x7E00)?; - let normal = fb.select(lost, quiet, normal)?; - // Only a denormal lane converts its magnitude (every other lane converts zero), so no - // conversion is out of range. - let min_normal = c(fb, 0x3880_0000)?; - let is_den = bin(fb, BinOp::ULessThan, a, min_normal)?; - let z = c(fb, 0)?; - let small = fb.select(is_den, a, z)?; - let wide = u.with(Held::Float(FloatFmt::F32)); - let ft = ty(fb, wide)?; - let af = fb.convert(ConvOp::Bitcast, small, ft)?; - let scale = fsplat(fb, wide, 16_777_216.0)?; - let scaled = bin(fb, BinOp::FMul, af, scale)?; - let ut = ty(fb, u)?; - let den = fb.convert(ConvOp::ConvertFToU, scaled, ut)?; - let r = fb.select(is_den, den, normal)?; - bin(fb, BinOp::BitwiseOr, sign, r) -} - /// The narrow value (an `f32` of form `f`) of format bits `h`, the low 16 bits of each `u32` /// lane; the bits above them are ignored, so a load need not clear them. /// diff --git a/crates/metal2vulkan/src/lower/arith/tests/narrow.rs b/crates/metal2vulkan/src/lower/arith/tests/narrow.rs index 3cb6fac52..c24bcf66f 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/narrow.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/narrow.rs @@ -92,9 +92,9 @@ fn bf16_values() -> Vec { /// /// The store of a loaded value reuses the bits it was decoded from, so the round trip runs twice: /// once through that reuse, and once through a copy of the value, which has no noted bits, so -/// `to_bits` runs its sequence: there a half NaN is the device's widening's (here the interpreter's -/// canonical NaN, `PrecisionNote::NativeNanEncoding`), and every other half and every bfloat -/// pattern comes back exactly. +/// `to_bits` encodes it: there a half NaN is the device's widening's and narrowing's (here the +/// interpreter's canonical NaN, `PrecisionNote::NativeNanEncoding`), and every other half and +/// every bfloat pattern comes back exactly. #[test] fn narrow_bits_round_trip_every_pattern() { for f in [half(), bfloat()] { @@ -109,7 +109,7 @@ fn narrow_bits_round_trip_every_pattern() { &|g, w| g == w, ); check_accept( - &format!("{f:?} round trip through the encode sequence"), + &format!("{f:?} round trip through the encode"), &[f], f, &|fb, x| fb.unary(UnOp::CopyObject, x[0]), @@ -129,11 +129,11 @@ fn narrow_bits_round_trip_every_pattern() { } } -/// One exact half round trip through its format bits, `to_bits` then `from_bits` (their constants -/// shared with the kernel's own load and store), is 160 words: each direction selects the normal or -/// special rebias and applies it once, where separate normal and special results took 170. A load -/// also decodes without masking the lane's low 16 bits first (the round trip test above feeds -/// `from_bits` junk above them). +/// 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 +/// without masking the lane's low 16 bits first (the round trip test above feeds `from_bits` junk +/// above them). #[test] fn a_half_round_trip_through_its_bits_is_compact() { use crate::spirv::serialize::serialize; @@ -141,7 +141,7 @@ fn a_half_round_trip_through_its_bits_is_compact() { let m = kernel(&[half()], half(), body).expect("build"); serialize(m).expect("serialize").words.len() }; - // Copies keep the decoded bits from being reused, so both sequences run. + // Copies keep the decoded bits from being reused, so both conversions run. let without = size(&|fb, x| fb.unary(UnOp::CopyObject, x[0])); let with = size(&|fb, x| { let c = fb.unary(UnOp::CopyObject, x[0])?; @@ -149,26 +149,20 @@ fn a_half_round_trip_through_its_bits_is_compact() { let y = super::super::narrow::from_bits(fb, half(), b)?; fb.unary(UnOp::CopyObject, y) }); - assert!(with - without <= 160, "{} words", with - without); + assert!(with - without <= 40, "{} words", with - without); } /// Under native half rounding a `half` may reach its store unrounded (the device folds the -/// conversion pair), and the store's bits then saturate: a finite magnitude from `65536` up is -/// infinity, never a NaN's code or a code past 16 bits (whose bit 17 a pair's store carried into -/// the next lane); every other value is truncated toward zero onto the half -/// grid, an infinity and a NaN as before, and a half value is its own bits. A module whose rounding -/// is Metal's takes no cap. +/// conversion pair), and the store's bits are then the device's narrowing of it, in either form +/// (its conversion to 16 bits, `PackHalf2x16` without `shaderFloat16`): here the interpreter's, to +/// nearest even on the half grid, half denormals kept, a finite magnitude from `65520` up the +/// infinity of its sign, never a NaN's code or a code past 16 bits (whose bit 17 a pair's store +/// would carry into the next lane), and a NaN a NaN; a half value is its own bits. The narrowing is +/// the same instructions whether the module's rounding is native or not. #[test] -fn an_unrounded_half_saturates_at_its_store_under_native_rounding() { - use super::super::narrow::{f32_of_half_bits, half_bits_of_f32}; - let truncated = |b: u32| -> u64 { - let a = b & 0x7FFF_FFFF; - let sign = (b >> 16) & 0x8000; - u64::from(match a { - 0x4780_0000..0x7F80_0000 => sign | 0x7C00, - _ => half_bits_of_f32(b), - }) - }; +fn an_unrounded_half_is_the_devices_narrowing_at_its_store() { + use super::super::narrow::f32_of_half_bits; + use crate::spirv::builder::QuantizeForm; let mut bits: Vec = vec![ 0x7F7F_FFFF, 0xFF7F_FFFF, @@ -176,12 +170,15 @@ fn an_unrounded_half_saturates_at_its_store_under_native_rounding() { 0x4780_0001, 0x477F_FFFF, 0x477F_F000, + 0x477F_EFFF, 0x477F_E000, 0x47C3_5000, 0x7149_F2CA, 0xC780_0000, 0x3F80_0001, + 0x3F80_1000, 0x3F80_1FFF, + 0x3F80_3000, 0x3649_539C, 0x3380_0001, 0x0000_0001, @@ -193,40 +190,154 @@ fn an_unrounded_half_saturates_at_its_store_under_native_rounding() { ]; bits.extend((0..=0xFFFFu32).step_by(7).map(f32_of_half_bits)); let cases: Vec = bits.iter().map(|&b| vec![vec![u64::from(b)]]).collect(); - let words = |native: bool| { + for q in [QuantizeForm::Converted, QuantizeForm::Device] { + let words = |native: bool| { + let body = move |fb: &mut FunctionBuilder<'_>, x: &[Value]| -> BResult { + fb.module().set_quantize_form(q); + fb.module().set_native_half(native); + Ok(x[0]) + }; + let m = kernel_with(&[float(32)], half(), &body, true, false).expect("build"); + crate::spirv::serialize::serialize(m) + .expect("serialize") + .words + .len() + }; let body = move |fb: &mut FunctionBuilder<'_>, x: &[Value]| -> BResult { - fb.module().set_native_half(native); + fb.module().set_quantize_form(q); + fb.module().set_native_half(true); Ok(x[0]) }; - let m = kernel_with(&[float(32)], half(), &body, true, false).expect("build"); - crate::spirv::serialize::serialize(m) - .expect("serialize") - .words - .len() - }; - let body = |fb: &mut FunctionBuilder<'_>, x: &[Value]| -> BResult { - fb.module().set_native_half(true); - Ok(x[0]) - }; - check_accept( - "native", - &[float(32)], - half(), - &body, - &cases, - &|c| Some(vec![truncated(arg(c, 0) as u32)]), - &|g, w| g == w, - ); - assert!( - words(false) < words(true), - "the cap is emitted only under native rounding" - ); + check_accept( + &format!("native {q:?}"), + &[float(32)], + half(), + &body, + &cases, + &|c| Some(vec![metal_half(arg(c, 0))]), + &|g, w| g == w || (is_nan(half(), g) && is_nan(half(), w)), + ); + assert_eq!( + words(false), + words(true), + "{q:?}: no cap under native rounding" + ); + } } -/// The host transliterations of the two bit sequences, which fold a constant's bits at translation -/// time, agree with the sequences' values on every half pattern (the widened value is the -/// pattern's, and back is the pattern itself), and a constant that is no half value (a lost NaN -/// payload, an `f32` between two halves) is not folded. +/// A `half`'s bits from its value, where none are known, are the device's narrowing on every form, +/// with no integer encode: wherever the module can hold a 16-bit float (`QuantizeForm::Converted` +/// and `Controlled`, a profile with `shaderFloat16`), one conversion of the lanes to 16 bits, read +/// as words beside a 16-bit zero, decorated `NoContraction` under the float controls; in +/// `QuantizeForm::Device` (no `shaderFloat16`), `GLSL.std.450 PackHalf2x16` of each lane beside a +/// zero (one a lane, and no 16-bit type). Every half value, on one to four lanes, encodes to its +/// own bits zero-extended but a NaN, which encodes to a NaN (`PrecisionNote::NativeNanEncoding`), +/// and `narrow::encodes_bits` finds the narrowing. +#[test] +fn a_half_encode_is_the_devices_narrowing_in_every_form() { + use super::super::narrow::{encodes_bits, f32_of_half_bits, half_bits_of_f32, to_bits}; + use crate::spirv::builder::QuantizeForm; + use crate::spirv::ir::Contraction; + let lanes_of = |n: u32| -> Vec { + (0..0x1_0000u32) + .step_by(n as usize) + .map(|h| { + vec![(h..h + n) + .map(|x| u64::from(f32_of_half_bits(x & 0xFFFF))) + .collect()] + }) + .collect() + }; + let want = |c: &Case| { + Some( + c[0].iter() + .map(|b| u64::from(half_bits_of_f32(*b as u32))) + .collect(), + ) + }; + let half_nan = |b: u64| b >> 16 == 0 && is_nan(half(), b); + for q in [ + QuantizeForm::Device, + QuantizeForm::Converted, + QuantizeForm::Controlled, + ] { + let float16 = q != QuantizeForm::Device; + for lanes in 1u8..=4 { + let cases = lanes_of(u32::from(lanes)); + let cases = &cases; + let what = format!("{lanes} lanes, {q:?}"); + let body = move |fb: &mut FunctionBuilder<'_>, x: &[Value]| -> BResult { + fb.module().set_quantize_form(q); + to_bits(fb, vec(half(), lanes), x[0]) + }; + let (ins, out) = ([vec(float(32), lanes)], vec(int(32), lanes)); + let m = kernel_with(&ins, out, &body, true, false) + .unwrap_or_else(|e| panic!("{what}: build: {e:?}")); + let budget = crate::budget::Budget::default(); + let mut meter = crate::budget::Meter::new(&budget); + assert!( + encodes_bits(&m, &mut meter).expect("encodes_bits"), + "{what}: encodes_bits" + ); + let insts = || m.blocks().iter().flat_map(|b| &b.insts); + let integer_encode = insts().any(|n| { + matches!( + n.inst, + Inst::Convert { + op: ConvOp::ConvertFToU, + .. + } | Inst::Select { .. } + ) + }); + let conversions: Vec = insts() + .filter_map(|n| match n.inst { + Inst::Convert { + op: ConvOp::FConvert, + contract, + .. + } => Some(contract), + _ => None, + }) + .collect(); + let packs = insts() + .filter(|n| { + matches!( + n.inst, + Inst::Glsl { + op: GlslOp::PackHalf2x16, + .. + } + ) + }) + .count(); + let halves = m + .types() + .iter() + .any(|(_, t)| matches!(t, Type::Float { width: 16 })); + let held = match q { + QuantizeForm::Controlled => Contraction::Forbidden, + _ => Contraction::Allowed, + }; + assert_eq!( + conversions, + vec![held; usize::from(float16)], + "{what}: the conversions" + ); + let want_packs = if float16 { 0 } else { usize::from(lanes) }; + assert_eq!(packs, want_packs, "{what}: the packs"); + assert_eq!(halves, float16, "{what}: a 16-bit float type"); + assert!(!integer_encode, "{what}: an integer encode"); + check_accept(&what, &ins, out, &body, cases, &want, &|g, w| { + g == w || (half_nan(g) && half_nan(w)) + }); + } + } +} + +/// The host's bits of a half value and value of half bits, which fold a constant's bits at +/// translation time, agree on every half pattern (the widened value is the pattern's, and back is +/// the pattern itself), and a constant that is no half value (a lost NaN payload, an `f32` between +/// two halves) is not folded. #[test] fn narrow_constant_bits_fold_exactly() { use super::super::narrow::{f32_of_half_bits, half_bits_of_f32}; @@ -252,7 +363,8 @@ fn narrow_constant_bits_fold_exactly() { assert_eq!(x == bits, folds, "{bits:#010x}"); } // A store of a constant takes its bits at translation time: the kernel's store of every - // tested constant equals the pattern (the encode sequence would compute the same). + // tested constant equals the pattern (the device's narrowing would compute the same but for a + // NaN's bits). for f in [half(), bfloat()] { let vals = if f == half() { half_values() @@ -287,11 +399,11 @@ fn narrow_constant_bits_fold_exactly() { /// in one lane of a 4-lane vector built from `undef`, is stored exactly as it was loaded (the junk /// the harness loads above each lane's 16 bits cleared); so is a vector that keeps two lanes of a /// loaded vector and replaces the other two; so is a chain one lane of which has no known bits (a -/// copy of a loaded lane), which runs the sequence; so is each lane stored alone, with and without -/// known vector bits; and the vector's widened lanes are the patterns' values. Where the sequence -/// runs, a `half` NaN's bits are the device's widening's (`PrecisionNote::NativeNanEncoding`): so -/// in a copy's chain, and in the loaded vector's, which the harness builds from its lanes' decodes -/// (a construct, whose bits are not noted). +/// copy of a loaded lane), which the device's narrowing encodes; so is each lane stored alone, with +/// and without known vector bits; and the vector's widened lanes are the patterns' values. Where +/// the narrowing encodes, a `half` NaN's bits are the device's +/// (`PrecisionNote::NativeNanEncoding`): so in a copy's chain, and in the loaded vector's, which +/// the harness builds from its lanes' decodes (a construct, whose bits are not noted). #[test] fn narrow_lanes_move_as_bits_through_vectors() { use super::super::narrow::note_insert; @@ -321,7 +433,7 @@ fn narrow_lanes_move_as_bits_through_vectors() { .collect(); let ins = [f, f, f, f]; let lanes = |c: &Case| Some((0..4).map(|i| arg(c, i)).collect()); - // Bits the sequence computes: a `half` NaN is the device's widening's. + // Bits the device's narrowing computes: a `half` NaN is the device's. let sequenced = |g: u64, w: u64| g == w || (f == half() && is_nan(f, g) && is_nan(f, w)); for copy in [None, Some(2)] { check_accept( @@ -413,9 +525,9 @@ fn narrow_lanes_move_as_bits_through_vectors() { /// Repeating a vector's lane inserts on bits never costs words. Four loaded halves stored as a /// vector need neither their decode nor the vector's encode once unread instructions are removed; a -/// chain one lane of which has no known bits costs what it did without the notes (the sequence -/// encodes the vector); and so does a lane stored from a vector whose bits are unknown (the lane is -/// encoded alone). +/// chain one lane of which has no known bits costs what it did without the notes (the device's +/// narrowing encodes the vector); and so does a lane stored from a vector whose bits are unknown +/// (the lane is encoded alone). #[test] fn narrow_lane_inserts_never_cost_words() { use super::super::narrow::note_insert; @@ -446,7 +558,7 @@ fn narrow_lane_inserts_never_cost_words() { let v4 = vec(half(), 4); let (with, without) = (size(v4, &chain(true, None)), size(v4, &chain(false, None))); assert!( - with + 100 < without, + with + 64 < without, "{with} words with notes, {without} without" ); let (with, without) = ( diff --git a/crates/metal2vulkan/src/lower/arith/tests/round_texel.rs b/crates/metal2vulkan/src/lower/arith/tests/round_texel.rs index 8dd69f7cf..9f9553fb9 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/round_texel.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/round_texel.rs @@ -4,10 +4,10 @@ //! The kernel reads `f32` words, the device's decode of an image texel, converts them as a texture //! access does, and stores the `half` bits. A half-float texel decodes to its exact `f32` value //! (a NaN to the `f32` NaN of its sign and payload), so the conversion must give the texel's own -//! bits back: every subnormal, both zeros, both infinities, the largest half, and every NaN -//! payload. A wider texel rounds to nearest even, half subnormals kept. `OpQuantizeToF16` alone -//! fails both: the interpreter gives a value below the smallest normal half as the zero of its -//! sign, and a NaN as `0x7E00`. +//! bits back: every subnormal, both zeros, both infinities and the largest half; a NaN stays a +//! NaN, its bits the store's narrowing's, the device's. A wider texel rounds to nearest even, half +//! subnormals kept. `OpQuantizeToF16` alone fails the subnormals: the interpreter gives a value +//! below the smallest normal half as the zero of its sign. use super::texel_round::half_probe_bits; use super::*; @@ -52,8 +52,10 @@ fn want(w: u64) -> u64 { } /// Every half bit pattern, widened as the device decodes a half-float texel, reads back as itself, -/// bit for bit: subnormals, zeros, infinities, `±65504`, and NaNs of every payload, signaling ones -/// included; one lane at a time and four at once, as a `half4` read holds them. +/// bit for bit: subnormals, zeros, infinities and `±65504`; a NaN of every payload, signaling ones +/// included, reads back as a NaN, its bits the device's narrowing's at the store +/// (`PrecisionNote::NativeNanEncoding`); one lane at a time and four at once, as a `half4` read +/// holds them. #[test] fn a_half_texel_keeps_every_bit_pattern() { // The reference is the identity on every widened half. @@ -61,6 +63,7 @@ fn a_half_texel_keeps_every_bit_pattern() { assert_eq!(want(widened(h)), u64::from(h), "{h:#06x}"); } let cases: Vec = (0..=0xFFFFu16).map(|h| vec![vec![widened(h)]]).collect(); + let same = |g: u64, w: u64| g == w || (is_nan(half(), g) && is_nan(half(), w)); check_accept( "half texel", &[float(32)], @@ -68,7 +71,7 @@ fn a_half_texel_keeps_every_bit_pattern() { &texel(1), &cases, &|c| Some(vec![want(arg(c, 0))]), - &|g, w| g == w, + &same, ); let lanes: Vec = (0..0x1_0000u32) .step_by(4) @@ -81,7 +84,7 @@ fn a_half_texel_keeps_every_bit_pattern() { &texel(4), &lanes, &|c| Some(c[0].iter().map(|w| want(*w)).collect()), - &|g, w| g == w, + &same, ); } @@ -189,7 +192,8 @@ fn unsigned_compares(m: &crate::spirv::ir::TypedModule) -> usize { /// the conversion's own rounding: every half-float texel and every wider value but a NaN reads as /// with the keep, to nearest even with half subnormals kept, and a NaN stays a NaN, without the /// keep's unsigned compare of the texel's bits. Without the flag the keep stands, and every half -/// bit pattern reads back as itself. +/// bit pattern reads back as itself, a NaN as a NaN (its bits the device's narrowing's at the +/// store). #[test] fn a_texel_under_the_float_controls_takes_the_conversions_nan_by_default() { use crate::spirv::builder::QuantizeForm; @@ -228,7 +232,7 @@ fn a_texel_under_the_float_controls_takes_the_conversions_nan_by_default() { &body, &halves, &|c| Some(vec![want(arg(c, 0))]), - &|g, w| g == w, + &|g, w| g == w || (is_nan(half(), g) && is_nan(half(), w)), ); } } diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index abc0d5cbf..7b31ebded 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -1705,7 +1705,8 @@ pub enum PrecisionNote { /// LLVM 23.1.1 and for a loaded texel on Mesa 26.0.8 with LLVM 21.1.8, barrier or not, whose /// arithmetic measured rounded. The result is then the `float` computation itself: its /// differences from Metal's compound across operations, and a value past the `half`'s range - /// stays finite until a `half` store saturates it to infinity. The RTX 5080 Laptop GPU on the + /// stays finite until a `half` store narrows it by the device's conversion (to infinity, or + /// to 65504 rounding toward zero). The RTX 5080 Laptop GPU on the /// same driver rounds here (8192 of 8192 sums Metal's); /// - on a device that rounds toward zero, a finite value from 65520 up is 65504 where /// Metal's is infinity; @@ -1718,16 +1719,19 @@ pub enum PrecisionNote { /// Every `half` a module reads from its bits (a load, a reinterpretation, a texel's bits) is /// the device's widening of them, on every device: an `OpFConvert` to 32 bits of the bits read /// as a 16-bit float with `shaderFloat16`, `GLSL.std.450 UnpackHalf2x16` of them without it. - /// A module that reads one records this note too where that widening is neither under the - /// float controls' `DenormPreserve` for 16 bits (ANV, RADV) nor measured to read every `half` - /// as Metal's (MoltenVK's conversion is, `DriverDeviation::MetalHalfArithmetic`, and the module - /// requires it there), so on every device without `shaderFloat16`: its bound is the last two - /// items', a half denormal read as the zero of its sign on a device that flushes 16-bit - /// denormals (the Vulkan spec lets a device flush a denormal "obtained via unpacking an - /// integer" without `DenormPreserve` for 16 bits, and gives `UnpackHalf2x16` - /// implementation-defined precision) and a NaN's bits the device's - /// ([`PrecisionNote::NativeNanEncoding`], which the module records); every other `half` - /// widens to its exact value. + /// So too every `half` a module encodes to its bits (a store, a reinterpretation, a texel's + /// bits) where they are not the bits it was read from: the device's narrowing of it, an + /// `OpFConvert` to 16 bits read as a word with `shaderFloat16`, `GLSL.std.450 PackHalf2x16` + /// without it. A module that reads or encodes one records this note too where that widening + /// or narrowing is neither under the float controls' `DenormPreserve` for 16 bits (ANV, RADV) + /// nor measured to read and narrow every `half` as Metal's (MoltenVK's conversion is, + /// `DriverDeviation::MetalHalfArithmetic`, and the module requires it there), so on every + /// device without `shaderFloat16`: its bound is the last two items', a half denormal read or + /// encoded as the zero of its sign on a device that flushes 16-bit denormals (the Vulkan spec + /// lets a device flush a denormal "obtained via unpacking an integer" without `DenormPreserve` + /// for 16 bits, and gives `UnpackHalf2x16` and `PackHalf2x16` implementation-defined + /// precision) and a NaN's bits the device's ([`PrecisionNote::NativeNanEncoding`], which the + /// module records); every other `half` widens to its exact value and encodes to its own bits. /// /// Validation derives no tolerance from it. NativeHalfConversion, @@ -1763,9 +1767,14 @@ pub enum PrecisionNote { /// without it), and a NaN widens to a NaN whose bits are the device's, where Metal widens /// 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 a select, a phi or a sign operation) may leave - /// with the device's bits; a `half` stored back unchanged keeps its bits. Every other `half` - /// widens to its value, but a denormal on a device that may flush 16-bit ones - /// ([`PrecisionNote::NativeHalfConversion`]). Validation derives no tolerance from it. + /// with the device's bits; a `half` stored back unchanged keeps its bits. 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 + /// narrows to a NaN whose bits are the device's, where Metal keeps a `half` NaN's sign and + /// payload. Every other `half` widens to its value and narrows to its bits, but a denormal on a + /// device that may flush 16-bit ones ([`PrecisionNote::NativeHalfConversion`]). Validation + /// derives no tolerance from it. NativeNanEncoding, /// Native device maths: Metal's `fmin`, `fmax`, `min3`, `max3`, `clamp` or `saturate` (its /// `clamp(x, +0, 1)`) on `float` or `half` is the device's `GLSL.std.450` `NMin`, `NMax` or diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index ee347b076..678cb8ac2 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -2590,13 +2590,14 @@ fn compile_kept( // module records the native note. let converts = quantize == crate::spirv::builder::QuantizeForm::Converted && crate::lower::arith::narrow::rounds_by_conversion(&module, m)?; - // A `half` read from its bits by the device's widening (every profile: `OpFConvert` with - // `shaderFloat16`, `UnpackHalf2x16` without): a NaN's bits are the device's, recorded. Under - // the float controls its denormals are Metal's, as the conversion's; on a device whose - // conversion's widening is measured to read every `half` as Metal's - // (`DriverDeviation::MetalHalfArithmetic`) the module requires that fact; elsewhere the device - // may flush them, within the native conversion's note. - let widens = crate::lower::arith::narrow::widens_bits(&module, m)?; + // A `half` read from its bits by the device's widening, or encoded to them by its narrowing + // (every profile: `OpFConvert` with `shaderFloat16`, `UnpackHalf2x16` and `PackHalf2x16` + // without): a NaN's bits are the device's, recorded. Under the float controls its denormals + // are Metal's, as the conversion's; on a device whose conversion is measured to read and + // narrow every `half` as Metal's (`DriverDeviation::MetalHalfArithmetic`) the module requires + // that fact; elsewhere the device may flush them, within the native conversion's note. + let widens = crate::lower::arith::narrow::widens_bits(&module, m)? + || crate::lower::arith::narrow::encodes_bits(&module, m)?; let measured_widening = widens && quantize == crate::spirv::builder::QuantizeForm::Converted && p.takes_driver_deviation(crate::error::DriverDeviation::MetalHalfArithmetic); diff --git a/crates/metal2vulkan/src/tests/engine_access.rs b/crates/metal2vulkan/src/tests/engine_access.rs index adc071ca9..4e1d3aa12 100644 --- a/crates/metal2vulkan/src/tests/engine_access.rs +++ b/crates/metal2vulkan/src/tests/engine_access.rs @@ -747,9 +747,9 @@ fn offsets(size: u64) -> Vec { /// Every leaf path, in-shader encoding, at offsets around the end of a 32-byte buffer and near 2^32 /// (with residuals 0 and 4 wrapping them further): no trap, exact in bounds, 0 or unchanged out of /// bounds. Probes are skipped where the offset breaks the access's stated alignment (undefined in -/// Metal). A `half` NaN loaded need only come back a NaN where the module reads a `half` from its -/// bits by the device's widening (`PrecisionNote::NativeNanEncoding`), whose NaN encoding is the -/// device's. +/// Metal). A `half` NaN loaded, or stored from a constant, need only come back a NaN where the +/// module reads a `half` from its bits by the device's widening or encodes one by its narrowing +/// (`PrecisionNote::NativeNanEncoding`), whose NaN encoding is the device's. #[test] fn every_leaf_path_is_exact_in_bounds_and_contained_out_of_bounds() { let size = 32u64; @@ -821,7 +821,15 @@ fn every_leaf_path_is_exact_in_bounds_and_contained_out_of_bounds() { if inb { want[at..at + bytes.len()].copy_from_slice(bytes); } - assert_eq!(out.buffers[0], want, "{what} r={r} off={off:#x}"); + if native_halves { + assert!( + same_halves(&out.buffers[0], &want), + "{what} r={r} off={off:#x}: {:?}", + out.buffers[0] + ); + } else { + assert_eq!(out.buffers[0], want, "{what} r={r} off={off:#x}"); + } } } } @@ -1048,9 +1056,10 @@ fn push_with_table(plan: &Plan) -> Vec { /// Every leaf path, with bind offsets 0 and 8, at offsets around the end of the allocation and near /// 2^32: no trap, exact in bounds, 0 out of bounds, and an out-of-bounds store lands in the sink /// and leaves the allocation unchanged. Robust buffer access does not cover device addresses, so -/// the check is emitted on a robust profile too. A `half` NaN loaded need only come back a NaN -/// where the module reads a `half` from its bits by the device's widening -/// (`PrecisionNote::NativeNanEncoding`), whose NaN encoding is the device's. +/// the check is emitted on a robust profile too. A `half` NaN loaded, or stored from a constant, +/// need only come back a NaN where the module reads a `half` from its bits by the device's +/// widening or encodes one by its narrowing (`PrecisionNote::NativeNanEncoding`), whose NaN +/// encoding is the device's. #[test] fn a_device_address_slot_is_exact_and_contained() { let size = 32u64; @@ -1138,7 +1147,15 @@ fn a_device_address_slot_is_exact_and_contained() { if inb { want[at..at + bytes.len()].copy_from_slice(bytes); } - assert_eq!(out.buffers[0], want, "{what} bind={bind} off={off:#x}"); + if native_halves { + assert!( + same_halves(&out.buffers[0], &want), + "{what} bind={bind} off={off:#x}: {:?}", + out.buffers[0] + ); + } else { + assert_eq!(out.buffers[0], want, "{what} bind={bind} off={off:#x}"); + } } } } @@ -1750,9 +1767,10 @@ fn profile_without(stem: &str, features: &[VkFeature]) -> DeviceProfile { /// 2023 baseline, both on `moltenvk-m3`), every generated leaf kernel is exact in bounds and /// contained out of bounds at bind residuals that are not multiples of 4: a narrow unit's index /// follows the binder contract (descriptor base congruent to the Metal address modulo 4), and a -/// sub-word store through a unit leaves its neighbours unchanged. A `half` NaN loaded need only -/// come back a NaN where the module reads a `half` from its bits by the device's widening -/// (`PrecisionNote::NativeNanEncoding`), whose NaN encoding is the device's. +/// sub-word store through a unit leaves its neighbours unchanged. A `half` NaN loaded, or stored +/// from a constant, need only come back a NaN where the module reads a `half` from its bits by the +/// device's widening or encodes one by its narrowing (`PrecisionNote::NativeNanEncoding`), whose +/// NaN encoding is the device's. #[test] fn narrow_units_are_exact_at_every_bind_residual() { let size = 32u64; @@ -1829,7 +1847,15 @@ fn narrow_units_are_exact_at_every_bind_residual() { if inb { want[at..at + bytes.len()].copy_from_slice(bytes); } - assert_eq!(out.buffers[0], want, "{what} r={r} off={o}"); + if native_halves { + assert!( + same_halves(&out.buffers[0], &want), + "{what} r={r} off={o}: {:?}", + out.buffers[0] + ); + } else { + assert_eq!(out.buffers[0], want, "{what} r={r} off={o}"); + } } } } @@ -2087,8 +2113,9 @@ const VEC4_RESIDUALS: [u32; 6] = [0, 4, 12, 16, 36, 0xFFFF_FFF0]; /// (declared beside the word view, and stored with one `OpStore`), in both encodings, on every /// tested profile; aligned to 4 it moves word by word (four stores, no `uvec4` view of the slot it /// stores to). At every residual a descriptor offset that is a multiple of 16 reads and writes -/// exactly the leaf's 16 bytes of a 48-byte range, and with the in-shader check the offset past -/// the range reads 0 and writes nothing. +/// exactly the leaf's 16 bytes of a 48-byte range (a `half` NaN stored from a constant a NaN where +/// the module encodes it by the device's narrowing, `PrecisionNote::NativeNanEncoding`), and with +/// the in-shader check the offset past the range reads 0 and writes nothing. #[test] fn sixteen_byte_leaves_move_as_one_uvec4() { const OP_STORE: u16 = 62; @@ -2120,6 +2147,8 @@ fn sixteen_byte_leaves_move_as_one_uvec4() { "{what}: views of out" ); let a = compile(&bc, k.name, &p).unwrap_or_else(|e| panic!("{what}: {e}")); + let native_halves = + k.ty.contains("half") && a.precision.contains(&PrecisionNote::NativeNanEncoding); let stores = opcodes(&a.module.words) .iter() .filter(|o| **o == OP_STORE) @@ -2169,7 +2198,15 @@ fn sixteen_byte_leaves_move_as_one_uvec4() { if inb { want[at..at + 16].copy_from_slice(bytes); } - assert_eq!(out.buffers[0], want, "{what} r={r:#x} {desc}"); + if native_halves { + assert!( + same_halves(&out.buffers[0], &want), + "{what} r={r:#x} {desc}: {:?}", + out.buffers[0] + ); + } else { + assert_eq!(out.buffers[0], want, "{what} r={r:#x} {desc}"); + } } } } diff --git a/crates/metal2vulkan/src/tests/engine_arith.rs b/crates/metal2vulkan/src/tests/engine_arith.rs index de3589365..58b00b761 100644 --- a/crates/metal2vulkan/src/tests/engine_arith.rs +++ b/crates/metal2vulkan/src/tests/engine_arith.rs @@ -3125,8 +3125,9 @@ fn stores_nan(bits: u32, half: bool) -> bool { /// on `lavapipe` and `moltenvk-m3`, each with its driver's deviation `MetalCanonicalNans` taken /// and not: the module selects no NaN, so it is the same word for word on both sides of the fact; /// it records `PrecisionNote::NativeNanEncoding` exactly where `noted(kernel, fact)` or it reads a -/// `half` from its bits by the device's widening (`narrow::widens_bits`: both profiles have -/// `shaderFloat16`), and never `DeviceNanEncoding`; and the interpreter's answer is the kernel's +/// `half` from its bits by the device's widening or encodes one by its narrowing +/// (`narrow::widens_bits`, `narrow::encodes_bits`: both profiles have `shaderFloat16`), and never +/// `DeviceNanEncoding`; and the interpreter's answer is the kernel's /// `want`, or a NaN, its bits the device's, where it has none, but for the kernels `unread` names, /// whose device instruction the interpreter does not evaluate. fn nans_are_the_device_s( @@ -3148,6 +3149,9 @@ fn nans_are_the_device_s( let (_, m) = crate::pipeline::testing::typed_module(bitcode, kk.name, &p) .unwrap_or_else(|e| panic!("{what}: {e:?}")); let widens = crate::lower::arith::narrow::widens_bits(&m, &mut meter()) + .and_then(|w| { + Ok(w || crate::lower::arith::narrow::encodes_bits(&m, &mut meter())?) + }) .unwrap_or_else(|e| panic!("{what}: {e:?}")); assert_eq!( a.precision.contains(&PrecisionNote::NativeNanEncoding), diff --git a/crates/metal2vulkan/src/tests/engine_fast_math_order.rs b/crates/metal2vulkan/src/tests/engine_fast_math_order.rs index 14de06470..f86ddeae0 100644 --- a/crates/metal2vulkan/src/tests/engine_fast_math_order.rs +++ b/crates/metal2vulkan/src/tests/engine_fast_math_order.rs @@ -397,7 +397,9 @@ fn chained_fast_math_notes_fast_math_rewrites() { } /// The `OpFConvert`s of `words` that narrow to 16 bits a value the module widened from 16 bits, or -/// a constant; and the count of 16-bit `OpFAdd`, `OpFSub` and `OpFMul`. +/// a constant; and the count of 16-bit `OpFAdd`, `OpFSub` and `OpFMul`. A widening of a narrowing +/// is a rounding's second half, which the builder keeps whole (a `half` store's narrowing reads +/// it), so it is no widened 16-bit value here. fn narrowings_of_halves(words: &[u32]) -> (Vec, usize) { use crate::spv::Op; let mut width = std::collections::BTreeMap::new(); @@ -427,10 +429,17 @@ fn narrowings_of_halves(words: &[u32]) -> (Vec, usize) { i += len; } let bits = |ty: u32| width.get(vector.get(&ty).unwrap_or(&ty)).copied(); + let narrowed: BTreeSet = converts + .iter() + .filter(|(ty, _, _)| bits(*ty) == Some(16)) + .map(|(_, id, _)| *id) + .collect(); let widened: BTreeSet = converts .iter() .filter(|(ty, _, x)| { - bits(*ty) == Some(32) && ty_of.get(x).and_then(|t| bits(*t)) == Some(16) + bits(*ty) == Some(32) + && ty_of.get(x).and_then(|t| bits(*t)) == Some(16) + && !narrowed.contains(x) }) .map(|(_, id, _)| *id) .collect(); diff --git a/crates/metal2vulkan/src/tests/engine_float_call_notes.rs b/crates/metal2vulkan/src/tests/engine_float_call_notes.rs index a5476cd76..f34397178 100644 --- a/crates/metal2vulkan/src/tests/engine_float_call_notes.rs +++ b/crates/metal2vulkan/src/tests/engine_float_call_notes.rs @@ -12,9 +12,10 @@ //! in that entry's math mode. The loads and stores around it record none, but a `half` kernel's //! widening and rounding, which the module records once by the profile's own form: its rounding's //! note (`narrow::native_rounding`), which the test sets aside, and a module's widening of a -//! `half` from its bits by the device (every profile), whose NaN's bits are the device's -//! (`narrow::widens_bits`, `NativeNanEncoding`), and without `shaderFloat16` its denormals too -//! (`UnpackHalf2x16`, `NativeHalfConversion`), which the test adds to the operation's notes. +//! `half` from its bits or narrowing of one to them by the device (every profile), whose NaN's +//! bits are the device's (`narrow::widens_bits`, `narrow::encodes_bits`, `NativeNanEncoding`), and +//! without `shaderFloat16` its denormals too (`UnpackHalf2x16`, `PackHalf2x16`, +//! `NativeHalfConversion`), which the test adds to the operation's notes. //! //! `llvm-as` assembles the modules; without it the test skips visibly. @@ -368,9 +369,10 @@ fn exported_float_notes_are_the_ones_a_compile_records() { } let (_, m) = typed_module(&bitcode, &k.name, p) .unwrap_or_else(|e| panic!("{what}: {e:?}")); - if narrow::widens_bits(&m, &mut meter()) - .unwrap_or_else(|e| panic!("{what}: {e:?}")) - { + let crosses = narrow::widens_bits(&m, &mut meter()) + .and_then(|w| Ok(w || narrow::encodes_bits(&m, &mut meter())?)) + .unwrap_or_else(|e| panic!("{what}: {e:?}")); + if crosses { want.insert(PrecisionNote::NativeNanEncoding); if form == crate::spirv::builder::QuantizeForm::Device { want.insert(PrecisionNote::NativeHalfConversion); diff --git a/docs/API.md b/docs/API.md index 9b6a720dd..5e4c7a51d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -3232,9 +3232,11 @@ bound. conversion under them, exactly, with no note): NVIDIA, whose driver folds the conversion's round trip even under those controls (`DriverWorkaround::HalfConversionPairFolded`), MoltenVK, lavapipe, and any device without them. Also recorded where a `half` read from its bits is the - device's widening and that widening is neither under those controls nor measured to be Metal's: - the conversion on NVIDIA and lavapipe, and `GLSL.std.450 UnpackHalf2x16` on every device without - `shaderFloat16`. A half denormal may read as the zero of its sign. + device's widening, or a `half` encoded to its bits (where they are not the bits it was read from) + is the device's narrowing, and that conversion is neither under those controls nor measured to be + Metal's: the conversion on NVIDIA and lavapipe, and `GLSL.std.450 UnpackHalf2x16` and + `PackHalf2x16` on every device without `shaderFloat16`. A half denormal may read or encode as the + zero of its sign. - `metal2vulkan-degrade-native-half-quantize` (precision). `PrecisionNote::NativeHalfQuantize`: Native half rounding (a quantize): the module rounds a `half` result it computes in `float` (a `half` operation's, a function's, a conversion from `float`'s, a texel's) by the device's @@ -3250,7 +3252,10 @@ bound. recorded wherever a `half` is read from its bits, on every device, since the read is the device's widening (its conversion with `shaderFloat16`, `UnpackHalf2x16` without): a NaN's bits the device's, where Metal widens every `half` NaN to `0x7fc00000` and moves one it does not - widen with its bits. + 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, 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. - `metal2vulkan-degrade-native-min-max` (precision). `PrecisionNote::NativeMinMax`: Native device maths: Metal's `fmin`, `fmax`, `min3`, `max3`, `clamp` or `saturate` (its `clamp(x, +0, 1)`) on `float` or `half` is the device's `GLSL.std.450` `NMin`, `NMax` or `NClamp`, on a device not diff --git a/docs/HOWTO.md b/docs/HOWTO.md index 94154e705..93788bc1d 100644 --- a/docs/HOWTO.md +++ b/docs/HOWTO.md @@ -49,8 +49,10 @@ pipeline records `NativeHalfConversion` or `NativeHalfQuantize`. NVIDIA's driver folds the pair (`DriverWorkaround::HalfConversionPairFolded`), so it takes the native conversion. A `half` read from memory or from its bits is the device's widening on every device (an `OpFConvert` of the bits read as a 16-bit float with `shaderFloat16`, `GLSL.std.450 -UnpackHalf2x16` without it), and the pipeline records `NativeNanEncoding` (a NaN's bits) and, -where that widening is neither under the float controls nor measured to be Metal's, +UnpackHalf2x16` without it), and a `half` stored or reinterpreted as bits, unless they are the +bits it was loaded from, the device's narrowing (an `OpFConvert` to 16 bits, `GLSL.std.450 +PackHalf2x16` without `shaderFloat16`); the pipeline records `NativeNanEncoding` (a NaN's bits) +and, where that conversion is neither under the float controls nor measured to be Metal's, `NativeHalfConversion` (a denormal the device may flush). To read AIR without translating it (list a metallib's functions, decode a module into typed IR,