From de5681429e93c53a03129fcd7683dc068b0696fb Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 20 Sep 2023 13:09:25 +0200 Subject: [PATCH] [msl-out] add min version check for `reverse_bits`, `extract_bits` & `insert_bits` --- src/back/msl/mod.rs | 2 ++ src/back/msl/writer.rs | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index f6ea6d42b9..76e0c39e1b 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -129,6 +129,8 @@ pub enum Error { CapabilityNotSupported(crate::valid::Capabilities), #[error("attribute '{0}' is not supported for target MSL version")] UnsupportedAttribute(String), + #[error("function '{0}' is not supported for target MSL version")] + UnsupportedFunction(String), #[error("can not use writeable storage buffers in fragment stage prior to MSL 1.2")] UnsupportedWriteableStorageBuffer, #[error("can not use writeable storage textures in {0:?} stage prior to MSL 1.2")] diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 5eebdaffa7..30310080b2 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -502,6 +502,7 @@ struct ExpressionContext<'a> { info: &'a valid::FunctionInfo, module: &'a crate::Module, pipeline_options: &'a PipelineOptions, + lang_version: (u8, u8), policies: index::BoundsCheckPolicies, /// A bitset containing the `Expression` handle indexes of expressions used @@ -1758,9 +1759,24 @@ impl Writer { Mf::CountTrailingZeros => "ctz", Mf::CountLeadingZeros => "clz", Mf::CountOneBits => "popcount", - Mf::ReverseBits => "reverse_bits", - Mf::ExtractBits => "extract_bits", - Mf::InsertBits => "insert_bits", + Mf::ReverseBits | Mf::ExtractBits | Mf::InsertBits => { + let name = match fun { + // reverse_bits is listed as requiring MSL 2.1 but that is copy/paste error. + // Looking at previous snapshots on web.archive.org it's present in MSL 1.2. + // + // https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html + // also talks about MSL 1.2 adding "New integer functions to extract, insert, and reverse bits, as described in Integer Functions." + Mf::ReverseBits => "reverse_bits", + Mf::ExtractBits => "extract_bits", + Mf::InsertBits => "insert_bits", + _ => unreachable!(), + }; + if context.lang_version < (1, 2) { + return Err(Error::UnsupportedFunction(name.to_string())); + } else { + name + } + } Mf::FindLsb => "", Mf::FindMsb => "", // data packing @@ -3566,6 +3582,7 @@ impl Writer { function: fun, origin: FunctionOrigin::Handle(fun_handle), info: fun_info, + lang_version: options.lang_version, policies: options.bounds_check_policies, guarded_indices, module, @@ -4150,6 +4167,7 @@ impl Writer { function: fun, origin: FunctionOrigin::EntryPoint(ep_index as _), info: fun_info, + lang_version: options.lang_version, policies: options.bounds_check_policies, guarded_indices, module,