Skip to content

Commit

Permalink
[msl-out] add min version check for reverse_bits, extract_bits & …
Browse files Browse the repository at this point in the history
…`insert_bits`
  • Loading branch information
teoxoy committed Sep 20, 2023
1 parent c90d022 commit de56814
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
24 changes: 21 additions & 3 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1758,9 +1759,24 @@ impl<W: Write> Writer<W> {
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
Expand Down Expand Up @@ -3566,6 +3582,7 @@ impl<W: Write> Writer<W> {
function: fun,
origin: FunctionOrigin::Handle(fun_handle),
info: fun_info,
lang_version: options.lang_version,
policies: options.bounds_check_policies,
guarded_indices,
module,
Expand Down Expand Up @@ -4150,6 +4167,7 @@ impl<W: Write> Writer<W> {
function: fun,
origin: FunctionOrigin::EntryPoint(ep_index as _),
info: fun_info,
lang_version: options.lang_version,
policies: options.bounds_check_policies,
guarded_indices,
module,
Expand Down

0 comments on commit de56814

Please sign in to comment.