Skip to content

Commit

Permalink
[msl-out] add min version checks for binding arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored and jimblandy committed Oct 17, 2023
1 parent f4a43b1 commit 46c4727
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ pub enum Error {
UnsupportedWriteableStorageTexture(crate::ShaderStage),
#[error("can not use read-write storage textures prior to MSL 1.2")]
UnsupportedRWStorageTexture,
#[error("array of '{0}' is not supported for target MSL version")]
UnsupportedArrayOf(String),
#[error("array of type '{0:?}' is not supported")]
UnsupportedArrayOfType(Handle<crate::Type>),
}

#[derive(Clone, Debug, PartialEq, thiserror::Error)]
Expand Down
59 changes: 59 additions & 0 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4010,6 +4010,65 @@ impl<W: Write> Writer<W> {
}
}

// Check min MSL version for binding arrays
match var.space {
crate::AddressSpace::Handle => match module.types[var.ty].inner {
crate::TypeInner::BindingArray { base, .. } => {
match module.types[base].inner {
crate::TypeInner::Sampler { .. } => {
if options.lang_version < (2, 0) {
return Err(Error::UnsupportedArrayOf(
"samplers".to_string(),
));
}
}
crate::TypeInner::Image { class, .. } => match class {
crate::ImageClass::Sampled { .. }
| crate::ImageClass::Depth { .. }
| crate::ImageClass::Storage {
access: crate::StorageAccess::LOAD,
..
} => {
// Array of textures since:
// - iOS: Metal 1.2 (check depends on https://github.com/gfx-rs/naga/issues/2164)
// - macOS: Metal 2

if options.lang_version < (2, 0) {
return Err(Error::UnsupportedArrayOf(
"textures".to_string(),
));
}
}
crate::ImageClass::Storage {
access: crate::StorageAccess::STORE,
..
} => {
// Array of write-only textures since:
// - iOS: Metal 2.2 (check depends on https://github.com/gfx-rs/naga/issues/2164)
// - macOS: Metal 2

if options.lang_version < (2, 0) {
return Err(Error::UnsupportedArrayOf(
"write-only textures".to_string(),
));
}
}
crate::ImageClass::Storage { .. } => {
return Err(Error::UnsupportedArrayOf(
"read-write textures".to_string(),
));
}
},
_ => {
return Err(Error::UnsupportedArrayOfType(base));
}
}
}
_ => {}
},
_ => {}
}

// the resolves have already been checked for `!fake_missing_bindings` case
let resolved = match var.space {
crate::AddressSpace::PushConstant => options.resolve_push_constants(ep).ok(),
Expand Down

0 comments on commit 46c4727

Please sign in to comment.