diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 093502740..98e603450 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2463,6 +2463,13 @@ or does not check is rebuilt from the generations' names, with young counted ful ### Known gaps of pipeline states +- A narrow integer's high bits (an 8- or 16-bit value held in a 32-bit word) are cleared by + `OpBitwiseAnd` by the width's mask on every device. NVIDIA's driver 615.71.09 on Ampere GA10x + dropped that mask after a signed clamp to exactly the narrow range, so such a kernel answered the + clamp's sign-extended words there; 620.70.06 answers right, and no card the runtime is run on has + that driver on that architecture. The other form, `OpBitFieldUExtract(x, 0, N)`, loses the + device on Intel's Windows driver 101.2145 (UHD 630) at a desktop's first pipelines, so it is not + used. Test: `tests::narrow`'s `every_device_zero_extends_a_narrow_clamped_sum`. - Some forms argument buffers take under `MTLArgumentBuffersTier1` or `MTLArgumentBuffersTier2`, which `Device::argument_buffers_support` answers, are not lowered by the translator's identity domains, which every state is translated under: a state over a function that holds one is diff --git a/crates/metal2vulkan-runtime/src/tests/narrow.rs b/crates/metal2vulkan-runtime/src/tests/narrow.rs index a79fc8148..1093cc8d6 100644 --- a/crates/metal2vulkan-runtime/src/tests/narrow.rs +++ b/crates/metal2vulkan-runtime/src/tests/narrow.rs @@ -2,9 +2,10 @@ //! kind: a kernel the translator compiles adds and subtracts two values sign-extended from 16 and //! from 8 bits, clamps each result signed to exactly its width's range, truncates it and //! zero-extends it. On every device the module clears the bits above each width with -//! `OpBitFieldUExtract(x, 0, N)`, never `OpBitwiseAnd` by the width's mask, which a driver's -//! compiler dropped after the clamp (NVIDIA 615.71.09 on Ampere GA10x answered sign-extended words; -//! 620.70.06 does not), and every word is zero-extended. +//! `OpBitwiseAnd` by the width's mask, never `OpBitFieldUExtract(x, 0, N)`, which Intel's Windows +//! driver 101.2145 loses its device on (a driver's compiler dropped the mask after the clamp on +//! NVIDIA 615.71.09 on Ampere GA10x, which answered sign-extended words; 620.70.06 does not), and +//! every word is zero-extended. //! //! `llvm-as` assembles the kernel; without it the test skips visibly. @@ -156,8 +157,8 @@ entry: (extracts, ands) } - /// The kernel, translated, clears its narrow results' high bits by extracts and answers every - /// word zero-extended on every device. + /// The kernel, translated, clears its narrow results' high bits by masks and answers every word + /// zero-extended on every device. #[test] fn every_device_zero_extends_a_narrow_clamped_sum() { let bitcode = match llvm_assemble_text(KERNEL) { @@ -179,8 +180,8 @@ entry: .compile_compute_pipeline(&descriptor, &Budget::standard()) .unwrap_or_else(|error| panic!("{name}: {error}")); let (extracts, ands) = masks(&pipeline.stage.spirv); - assert!(extracts >= 4, "{name}: {extracts} extracts"); - assert_eq!(ands, 0, "{name}: masks by a narrow width's bits"); + assert!(ands >= 4, "{name}: {ands} masks by a narrow width's bits"); + assert_eq!(extracts, 0, "{name}: {extracts} extracts"); let state = device .new_compute_pipeline_state(&descriptor, crate::tests::no_constexpr_samplers) .unwrap_or_else(|error| panic!("{name}: {error}")); diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index c51e1c8ab..bb78ccd5d 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -61,7 +61,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 = 2208; +pub const SEMANTICS_VERSION: u32 = 2211; /// 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/ops.rs b/crates/metal2vulkan/src/lower/arith/ops.rs index 4c50f3e6a..e6b9cde4f 100644 --- a/crates/metal2vulkan/src/lower/arith/ops.rs +++ b/crates/metal2vulkan/src/lower/arith/ops.rs @@ -127,26 +127,16 @@ pub fn fsplat(fb: &mut FunctionBuilder<'_>, f: Form, x: f64) -> BResult { splat(fb, f, f.const_bits(x)) } -/// `x` with the bits above its AIR width cleared (a no-op for a full-width integer): in a 32-bit -/// container `OpBitFieldUExtract(x, 0, N)`, on every device, else `x & (2^N - 1)`, the same bits. -/// No driver can drop the extract as one did the mask after a signed clamp to exactly the narrow -/// range (NVIDIA 615.71.09 on Ampere GA10x answered the clamp's sign-extended words). +/// `x` with the bits above its AIR width cleared (a no-op for a full-width integer): `x & (2^N - +/// 1)`, on every device. `OpBitFieldUExtract(x, 0, N)` gives the same bits, but Intel's Windows +/// driver 101.2145 on the UHD 630 loses its device on a desktop's first pipelines in that form, so +/// the mask is the one form. NVIDIA 615.71.09 on Ampere GA10x dropped this mask after a signed +/// clamp to exactly the narrow range (it answered sign-extended words); 620.70.06 does not, and no +/// card we run has that driver on that architecture (the runtime's README, known gaps). pub fn mask(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult { if !f.legalized() { return Ok(x); } - if f.container() == 32 { - let u32_ = Form { - held: Held::Int { - bits: 32, - container: 32, - }, - lanes: 1, - }; - let zero = splat(fb, u32_, 0)?; - let width = splat(fb, u32_, u64::from(f.bits()))?; - return fb.bit_field_extract(false, x, zero, width); - } let m = splat(fb, f, ones(f.bits()))?; fb.binary(BinOp::BitwiseAnd, x, m) } diff --git a/crates/metal2vulkan/src/lower/arith/tests.rs b/crates/metal2vulkan/src/lower/arith/tests.rs index 3350a702d..0b7217f77 100644 --- a/crates/metal2vulkan/src/lower/arith/tests.rs +++ b/crates/metal2vulkan/src/lower/arith/tests.rs @@ -1946,13 +1946,13 @@ fn signed_narrow_saturation_clamps_without_signed_min_or_max() { } } -/// A narrow integer's mask in a 32-bit container is `OpBitFieldUExtract(x, 0, N)` and never -/// `OpBitwiseAnd`, and the source-arithmetic shape whose mask a driver dropped (NVIDIA 615.71.09 -/// on Ampere GA10x) answers its definition at every edge: two values sign-extended from `N` bits, +/// A narrow integer's mask in a 32-bit container is `OpBitwiseAnd` by `2^N - 1` and never +/// `OpBitFieldUExtract`, and the source-arithmetic shape whose mask a driver dropped (NVIDIA +/// 615.71.09 on Ampere GA10x) answers its definition at every edge: two values sign-extended from `N` bits, /// added or subtracted, clamped signed to exactly `N` bits' range (`SClamp`, and `SMin` then /// `SMax`), truncated to `N` bits. At 8 and 16 bits, scalar and three lanes. #[test] -fn a_narrow_mask_after_a_signed_clamp_is_an_extract() { +fn a_narrow_mask_after_a_signed_clamp_is_an_and() { let mut rng = Rng(0x0D0D_0D0E); for bits in [8u8, 16] { let vals = int_values(bits, &mut rng, 3); @@ -1996,8 +1996,8 @@ fn a_narrow_mask_after_a_signed_clamp_is_an_extract() { ) }) .count(); - assert!(extracts > 0, "{what}: no extract"); - assert_eq!(ands, 0, "{what}: a mask"); + assert!(ands > 0, "{what}: no mask"); + assert_eq!(extracts, 0, "{what}: an extract"); let usize_lanes = usize::from(lanes); let mut cases: Vec = Vec::new(); for (i, x) in vals.iter().enumerate() {