From f4a43b1bf07af3e72f95b35e284eb2ac5724ca10 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 20 Sep 2023 13:24:44 +0200 Subject: [PATCH] [msl-out] add min version check for read-write storage textures --- src/back/msl/mod.rs | 2 + src/back/msl/writer.rs | 84 +++++++++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index 76e0c39e1b..7b32ce80d7 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -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)] diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index ecec0d70b9..c17e84216c 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -3955,39 +3955,65 @@ impl Writer { if usage.is_empty() || var.space == crate::AddressSpace::Private { continue; } + + if options.lang_version < (1, 2) { + match var.space { + // This restriction is not documented in the MSL spec + // but validation will fail if it is not upheld. + // + // We infer the required version from the "Function + // Buffer Read-Writes" section of [what's new], where + // the feature sets listed correspond with the ones + // supporting MSL 1.2. + // + // [what's new]: https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html + 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 restriction is not documented in the MSL spec + // but validation will fail if it is not upheld. + // + // We infer the required version from the "Function + // Texture Read-Writes" section of [what's new], where + // the feature sets listed correspond with the ones + // supporting MSL 1.2. + // + // [what's new]: https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/WhatsNewiniOS10tvOS10andOSX1012/WhatsNewiniOS10tvOS10andOSX1012.html + 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(),