From 0340c2e685a3c8ec5d0c55192ae3af48f2c3962f Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 20 Sep 2023 12:29:29 +0200 Subject: [PATCH] [msl] add undocumented checks --- src/back/msl/mod.rs | 4 ++++ src/back/msl/writer.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index a5c713965..cb4e72397 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -129,6 +129,10 @@ pub enum Error { CapabilityNotSupported(crate::valid::Capabilities), #[error("attribute '{0}' is not supported for target MSL version")] UnsupportedAttribute(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")] + UnsupportedWriteableStorageTexture(crate::ShaderStage), } #[derive(Clone, Debug, PartialEq, thiserror::Error)] diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index bdb0b0ac3..64808c001 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -3940,6 +3940,35 @@ impl Writer { 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(),