Skip to content

Commit

Permalink
[msl-out] add min version check for read-write storage textures
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored and jimblandy committed Oct 17, 2023
1 parent b4952fd commit 655f707
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ pub enum Error {
UnsupportedWriteableStorageBuffer,
#[error("can not use writeable storage textures in {0:?} stage prior to MSL 1.2")]
UnsupportedWriteableStorageTexture(crate::ShaderStage),
#[error("can not use read-write storage textures prior to MSL 1.2")]
UnsupportedRWStorageTexture,
}

#[derive(Clone, Debug, PartialEq, thiserror::Error)]
Expand Down
72 changes: 43 additions & 29 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3953,39 +3953,53 @@ impl<W: Write> Writer<W> {
if usage.is_empty() || var.space == crate::AddressSpace::Private {
continue;
}

if options.lang_version < (1, 2) {
match var.space {
// This restriciton is not documented in the MSL spec but validation will fail if not upheld.
// We imply the version check from the "Function Buffer Read-Writes" section of https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html
// where the feaure sets listed correspond with the ones supporting MSL 1.2.
crate::AddressSpace::Storage { access }
if access.contains(crate::StorageAccess::STORE)
&& ep.stage == crate::ShaderStage::Fragment =>
{
return Err(Error::UnsupportedWriteableStorageBuffer)
}
crate::AddressSpace::Handle => {
match module.types[var.ty].inner {
crate::TypeInner::Image {
class: crate::ImageClass::Storage { access, .. },
..
} => {
// This restriciton is not documented in the MSL spec but validation will fail if not upheld.
// We imply the version check from the "Function Texture Read-Writes" section of https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html
// where the feaure set listed corresponds with the one supporting MSL 1.2.
if access.contains(crate::StorageAccess::STORE)
&& (ep.stage == crate::ShaderStage::Vertex
|| ep.stage == crate::ShaderStage::Fragment)
{
return Err(Error::UnsupportedWriteableStorageTexture(
ep.stage,
));
}

if access.contains(
crate::StorageAccess::LOAD | crate::StorageAccess::STORE,
) {
return Err(Error::UnsupportedRWStorageTexture);
}
}
_ => {}
}
}
_ => {}
}
}

// 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(),
crate::AddressSpace::WorkGroup => None,
// This restriciton is not documented in the MSL spec but validation will fail if not upheld.
// We imply the version check from the "Function Buffer Read-Writes" section of https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html
// where the feaure sets listed correspond with the ones supporting MSL 1.2.
crate::AddressSpace::Storage { access }
if access.contains(crate::StorageAccess::STORE)
&& options.lang_version < (1, 2)
&& ep.stage == crate::ShaderStage::Fragment =>
{
return Err(Error::UnsupportedWriteableStorageBuffer)
}
// This restriciton is not documented in the MSL spec but validation will fail if not upheld.
// We imply the version check from the "Function Texture Read-Writes" section of https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html
// where the feaure set listed corresponds with the one supporting MSL 1.2.
crate::AddressSpace::Handle
if match module.types[var.ty].inner {
crate::TypeInner::Image {
class: crate::ImageClass::Storage { access, .. },
..
} => {
access.contains(crate::StorageAccess::STORE)
&& options.lang_version < (1, 2)
&& (ep.stage == crate::ShaderStage::Vertex
|| ep.stage == crate::ShaderStage::Fragment)
}
_ => false,
} =>
{
return Err(Error::UnsupportedWriteableStorageTexture(ep.stage))
}
_ => options
.resolve_resource_binding(ep, var.binding.as_ref().unwrap())
.ok(),
Expand Down

0 comments on commit 655f707

Please sign in to comment.