From 7be524592aa66aaaf00926519c093a694bdb98e2 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 30 Mar 2021 15:18:06 -0400 Subject: [PATCH] [msl] fix mutability of function parameters --- src/back/msl/writer.rs | 44 ++++++++++++++++++++++-------------- tests/out/quad-vert.msl.snap | 8 +++---- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 2964a92449..83090a30bf 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -33,33 +33,40 @@ struct TypedGlobalVariable<'a> { names: &'a FastHashMap, handle: Handle, usage: GlobalUse, + reference: bool, } impl<'a> TypedGlobalVariable<'a> { fn try_fmt(&self, out: &mut W) -> Result<(), Error> { let var = &self.module.global_variables[self.handle]; let name = &self.names[&NameKey::GlobalVariable(self.handle)]; - let ty = &self.module.types[var.ty]; let ty_name = &self.names[&NameKey::Type(var.ty)]; - let (space_qualifier, reference) = match ty.inner { - crate::TypeInner::Struct { .. } => match var.class { - crate::StorageClass::Uniform | crate::StorageClass::Storage => { - let space = if self.usage.contains(GlobalUse::WRITE) { - "device " - } else { - "constant " - }; - (space, "&") - } - _ => ("", ""), - }, - _ => ("", ""), + let (space, access, reference) = match var.class.get_name(self.usage) { + Some(space) if self.reference => { + let access = match var.class { + crate::StorageClass::Private | crate::StorageClass::WorkGroup + if !self.usage.contains(GlobalUse::WRITE) => + { + "const" + } + _ => "", + }; + (space, access, "&") + } + _ => ("", "", ""), }; + Ok(write!( out, - "{}{}{} {}", - space_qualifier, ty_name, reference, name + "{}{}{}{}{}{} {}", + space, + if space.is_empty() { "" } else { " " }, + ty_name, + if access.is_empty() { "" } else { " " }, + access, + reference, + name, )?) } } @@ -123,7 +130,7 @@ impl crate::StorageClass { Self::Storage => Some(if global_use.contains(GlobalUse::WRITE) { "device" } else { - "storage" + "constant" }), Self::Private | Self::Function => Some("thread"), Self::WorkGroup => Some("threadgroup"), @@ -1243,6 +1250,7 @@ impl Writer { names: &self.names, handle, usage: fun_info[handle], + reference: true, }; let separator = separate(index + 1 != pass_through_globals.len()); write!(self.out, "{}", INDENT)?; @@ -1444,6 +1452,7 @@ impl Writer { names: &self.names, handle, usage, + reference: true, }; let separator = if is_first_argument { is_first_argument = false; @@ -1479,6 +1488,7 @@ impl Writer { names: &self.names, handle, usage, + reference: false, }; write!(self.out, "{}", INDENT)?; tyvar.try_fmt(&mut self.out)?; diff --git a/tests/out/quad-vert.msl.snap b/tests/out/quad-vert.msl.snap index 716b77bbb1..a3677ef4c9 100644 --- a/tests/out/quad-vert.msl.snap +++ b/tests/out/quad-vert.msl.snap @@ -36,10 +36,10 @@ struct type10 { type6 gl_ClipDistance1; }; void main1( - type1 v_uv, - type1 a_uv, - gl_PerVertex _, - type1 a_pos + thread type1& v_uv, + thread type1 const& a_uv, + thread gl_PerVertex& _, + thread type1 const& a_pos ) { v_uv = a_uv; type1 _expr9 = a_pos;