diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index c73c7b500..02b9b078b 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -2937,6 +2937,9 @@ degradations! { /// device's, where Metal reads `0x7FC00000`. Not bounded: a NaN in a sum makes the sum a /// NaN. NativeFloat8 = "native-float8"; + /// Class: reconvergence. The stage's reconvergence after divergence is the device's, where + /// Metal's is maximal; announced beside `ImplementationDefinedReconvergence`. + DeviceReconvergence = "device-reconvergence"; } } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs index 588225c3e..905d9a1a2 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison.rs @@ -341,7 +341,8 @@ pub fn allowance(note: PrecisionNote) -> Allowance { | N::UnorderedFetchWithinDraw | N::NativeLogicOperation | N::NativeFloat8 - | N::CappedLodBias => Allowance::Unbounded, + | N::CappedLodBias + | N::DeviceReconvergence => Allowance::Unbounded, } } diff --git a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs index 84cbcdd34..d7d77d848 100644 --- a/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs +++ b/crates/metal2vulkan-validation/src/observation_contract/comparison/tests.rs @@ -80,6 +80,7 @@ fn every_precision_note_has_its_table_row() { (N::NativeLogicOperation, Allowance::Unbounded), (N::NativeFloat8, Allowance::Unbounded), (N::CappedLodBias, Allowance::Unbounded), + (N::DeviceReconvergence, Allowance::Unbounded), ]; for (note, expected) in rows { assert_eq!(allowance(note), expected, "{note:?}"); diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index 8589a86a3..5e424e7ed 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -1527,6 +1527,7 @@ codec_enum! { NativeLogicOperation, NativeFloat8, CappedLodBias, + DeviceReconvergence, } BindingSource { Buffer(f0), Texture(f0), Sampler(f0), CombinedTextureSampler { texture, sampler }, diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index df99a56b1..942feb7ac 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 = 2148; +pub const SEMANTICS_VERSION: u32 = 2149; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -71,7 +71,7 @@ pub const SEMANTICS_VERSION: u32 = 2148; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 527; +pub const ARTIFACT_FORMAT_VERSION: u32 = 528; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index bd757d3ba..2fa606e95 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -2385,6 +2385,18 @@ pub enum PrecisionNote { /// /// Validation derives no tolerance from it. CappedLodBias, + /// The stage holds a tangled instruction (a simdgroup or quad operation, or a barrier whose + /// lanes depend on reconvergence) on a device without maximal reconvergence + /// (`Reconvergence::ImplementationDefined`): after divergent control flow the device decides + /// which lanes run it together, where Metal's lanes reconverge maximally, so such an operation + /// may see other lanes active than Metal's. Under subgroup-uniform control flow + /// (`shaderSubgroupUniformControlFlow`) the lanes reconverge where control flow is uniform. + /// Static per stage: recorded for any tangled instruction in the entry, as the stage's + /// `reconvergence` is. + /// + /// Validation derives no tolerance from it: a difference stays a mismatch, which the note + /// explains. + DeviceReconvergence, } /// The math mode of an entry's module, which decides, on a device whose `float` functions are diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index d91aa5d87..b8ee14feb 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -49,7 +49,7 @@ use crate::library::{ }; use crate::lower::dispatch::LocalSizeForm; use crate::lower::select::{LowerInputs, Plan}; -use crate::pipeline::artifact::{PrecisionNote, StrategyCensus, StrategyUse}; +use crate::pipeline::artifact::{PrecisionNote, Reconvergence, StrategyCensus, StrategyUse}; use crate::pipeline::compile::key::{DynamicKey, LinkedKey}; use crate::pipeline::descriptor::{ ColorAttachmentDescriptor, DynamicLibraries, FunctionDescriptor, LinkedFunction, @@ -3317,15 +3317,22 @@ fn compile_bounded( .insert(VkFeature::ShaderSampleRateInterpolationFunctions); } } + // Implementation-defined where a tangled instruction runs without maximal reconvergence + // (`lower::simd` chooses the entry's reconvergence mode), which the stage's note records. + let reconvergence = crate::lower::simd::reconvergence(&plan); + if reconvergence == Reconvergence::ImplementationDefined + && !precision.contains(&PrecisionNote::DeviceReconvergence) + { + precision.push(PrecisionNote::DeviceReconvergence); + precision.sort_unstable(); + } let artifact = Arc::new(FunctionArtifact { key, module, interface, facts: plan.facts.clone(), subgroup: plan.subgroup, - // Implementation-defined where a tangled instruction runs without maximal reconvergence - // (`lower::simd` chooses the entry's reconvergence mode). - reconvergence: crate::lower::simd::reconvergence(&plan), + reconvergence, precision, strategies: emitted_census(&plan, helper_guard), stats, diff --git a/crates/metal2vulkan/src/tests/engine_simd.rs b/crates/metal2vulkan/src/tests/engine_simd.rs index 15b9a0256..4684e5ea0 100644 --- a/crates/metal2vulkan/src/tests/engine_simd.rs +++ b/crates/metal2vulkan/src/tests/engine_simd.rs @@ -636,6 +636,7 @@ fn reconvergence_follows_the_profile() { let (_, words) = link_and_validate(&a, &maximal).expect("valid"); assert!(spirv_dis(&words).contains("MaximallyReconvergesKHR")); assert_eq!(a.reconvergence, Reconvergence::Guaranteed); + assert!(!a.precision.contains(&PrecisionNote::DeviceReconvergence)); let pascal = profile("nvidia-pascal-linux", DevicePolicy::default()).expect("profile"); let sg = pascal.fields().subgroup; @@ -648,6 +649,8 @@ fn reconvergence_follows_the_profile() { && !text.contains("SubgroupUniformControlFlowKHR") ); assert_eq!(a.reconvergence, Reconvergence::ImplementationDefined); + // The stage records the device's reconvergence as a note. + assert!(a.precision.contains(&PrecisionNote::DeviceReconvergence)); } /// Float sums record the device's association order. @@ -1023,6 +1026,7 @@ fn uniform_control_flow_mode_without_maximal_reconvergence() { .extensions .contains(&VkExtension::KhrShaderSubgroupUniformControlFlow)); assert_eq!(a.reconvergence, Reconvergence::ImplementationDefined); + assert!(a.precision.contains(&PrecisionNote::DeviceReconvergence)); } const HEADER: &str = "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32\"\ntarget triple = \"air64_v28-apple-macosx26.0.0\"\n\n"; diff --git a/crates/metal2vulkan/src/tests/fast_paths.rs b/crates/metal2vulkan/src/tests/fast_paths.rs index fc27e51a2..4cd86f21a 100644 --- a/crates/metal2vulkan/src/tests/fast_paths.rs +++ b/crates/metal2vulkan/src/tests/fast_paths.rs @@ -182,6 +182,7 @@ fn notes() -> Vec<(&'static str, Ledger)> { NativeFloat8, ], Elsewhere: [ + DeviceReconvergence, HalfOutputPrecision, NativeHalfConversion, NativeHalfQuantize, diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index ef37bee47..0d59413fc 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -6227,6 +6227,7 @@ macro-member metal2vulkan-runtime::Degradation::DeviceNanEncoding DeviceNanEncod macro-member metal2vulkan-runtime::Degradation::DevicePackConversion DevicePackConversion = "device-pack-conversion"; macro-member metal2vulkan-runtime::Degradation::DevicePointSize DevicePointSize = "device-point-size"; macro-member metal2vulkan-runtime::Degradation::DeviceRayIntersection DeviceRayIntersection = "device-ray-intersection"; +macro-member metal2vulkan-runtime::Degradation::DeviceReconvergence DeviceReconvergence = "device-reconvergence"; macro-member metal2vulkan-runtime::Degradation::DeviceRecovered DeviceRecovered = "device-recovered", Performance, macro-member metal2vulkan-runtime::Degradation::DeviceRoundedResolve DeviceRoundedResolve = "device-rounded-resolve", Precision, macro-member metal2vulkan-runtime::Degradation::DeviceSampleLevel DeviceSampleLevel = "device-sample-level"; @@ -12781,6 +12782,7 @@ variant metal2vulkan-rt::PrecisionNote::DeviceNanEncoding DeviceNanEncoding variant metal2vulkan-rt::PrecisionNote::DevicePackConversion DevicePackConversion variant metal2vulkan-rt::PrecisionNote::DevicePointSize DevicePointSize variant metal2vulkan-rt::PrecisionNote::DeviceRayIntersection DeviceRayIntersection +variant metal2vulkan-rt::PrecisionNote::DeviceReconvergence DeviceReconvergence variant metal2vulkan-rt::PrecisionNote::DeviceSampleLevel DeviceSampleLevel variant metal2vulkan-rt::PrecisionNote::DeviceSampling DeviceSampling variant metal2vulkan-rt::PrecisionNote::DeviceSignedZeroInfNan DeviceSignedZeroInfNan @@ -15624,6 +15626,7 @@ variant metal2vulkan::pipeline::PrecisionNote::DeviceNanEncoding DeviceNanEncodi variant metal2vulkan::pipeline::PrecisionNote::DevicePackConversion DevicePackConversion variant metal2vulkan::pipeline::PrecisionNote::DevicePointSize DevicePointSize variant metal2vulkan::pipeline::PrecisionNote::DeviceRayIntersection DeviceRayIntersection +variant metal2vulkan::pipeline::PrecisionNote::DeviceReconvergence DeviceReconvergence variant metal2vulkan::pipeline::PrecisionNote::DeviceSampleLevel DeviceSampleLevel variant metal2vulkan::pipeline::PrecisionNote::DeviceSampling DeviceSampling variant metal2vulkan::pipeline::PrecisionNote::DeviceSignedZeroInfNan DeviceSignedZeroInfNan diff --git a/docs/API.md b/docs/API.md index be2c79abf..660f9400e 100644 --- a/docs/API.md +++ b/docs/API.md @@ -5345,6 +5345,14 @@ bound. reads them, and records none. An `air.convert` from `f8e4m3fn` or `f8e5m2` and a simdgroup-matrix cell of those formats widen through the same type there and record none: their formats are OCP's own, and Metal on Apple M3 does not compile them. +- `metal2vulkan-degrade-device-reconvergence` (precision). `PrecisionNote::DeviceReconvergence`: A + stage holds a simdgroup or quad operation, or a barrier whose lanes depend on reconvergence, on a + device without maximal reconvergence (`Reconvergence::ImplementationDefined`): after divergent + control flow the device decides which lanes run it together, where Metal's reconverge maximally, + so the operation may see other lanes active than Metal's. With + `shaderSubgroupUniformControlFlow` the lanes reconverge where control flow is uniform. Recorded + for any such instruction in the stage's entry; `metal2vulkan-runtime` also announces + `ImplementationDefinedReconvergence` there. - `metal2vulkan-degrade-device-pack-conversion` (precision). `PrecisionNote::DevicePackConversion`: Native device maths (a conversion): `air.pack` or `air.unpack` of a normalized format is the device's: `GLSL.std.450`'s `Pack`/`Unpack` `Unorm4x8`, `Snorm4x8`, `Unorm2x16` and `Snorm2x16`,