From 1476ef84ffa2b450c2a2630b0afacf5551662847 Mon Sep 17 00:00:00 2001 From: Igor Shaposhnik Date: Tue, 4 May 2021 12:59:27 +0000 Subject: [PATCH] [spv-in] Fix empty gl_PerVertex name --- src/front/spv/mod.rs | 14 +++++++++++++- tests/out/quad-vert.msl | 10 +++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 052120c81..c7b77830d 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -363,6 +363,7 @@ struct Assignment { value: Handle, } +#[derive(PartialEq)] enum ExtendedClass { Global(crate::StorageClass), Input, @@ -3303,7 +3304,7 @@ impl> Parser { } else { None }; - let dec = self.future_decor.remove(&id).unwrap_or_default(); + let mut dec = self.future_decor.remove(&id).unwrap_or_default(); let original_ty = self.lookup_type.lookup(type_id)?.handle; let (effective_ty, is_storage) = match module.types[original_ty].inner { @@ -3322,6 +3323,17 @@ impl> Parser { map_storage_class(storage_class)? }; + // Fix empty name for gl_PerVertex struct generated by glslang + if let crate::TypeInner::Pointer { .. } = module.types[original_ty].inner { + if ext_class == ExtendedClass::Input || ext_class == ExtendedClass::Output { + if let Some(ref dec_name) = dec.name { + if dec_name.is_empty() { + dec.name = Some("perVertexStruct".to_string()) + } + } + } + } + let (inner, var) = match ext_class { ExtendedClass::Global(class) => { let storage_access = if is_storage { diff --git a/tests/out/quad-vert.msl b/tests/out/quad-vert.msl index 584a9a748..d7363aad4 100644 --- a/tests/out/quad-vert.msl +++ b/tests/out/quad-vert.msl @@ -20,12 +20,12 @@ struct type10 { void main1( thread metal::float2& v_uv, thread metal::float2 const& a_uv, - thread gl_PerVertex& _, + thread gl_PerVertex& perVertexStruct, thread metal::float2 const& a_pos ) { v_uv = a_uv; metal::float2 _e13 = a_pos; - _.gl_Position = metal::float4(_e13.x, _e13.y, 0.0, 1.0); + perVertexStruct.gl_Position = metal::float4(_e13.x, _e13.y, 0.0, 1.0); return; } @@ -44,13 +44,13 @@ vertex main2Output main2( ) { metal::float2 v_uv = {}; metal::float2 a_uv = {}; - gl_PerVertex _ = {}; + gl_PerVertex perVertexStruct = {}; metal::float2 a_pos = {}; const auto a_uv1 = varyings.a_uv1; const auto a_pos1 = varyings.a_pos1; a_uv = a_uv1; a_pos = a_pos1; - main1(v_uv, a_uv, _, a_pos); - const auto _tmp = type10 {v_uv, _.gl_Position, _.gl_PointSize, _.gl_ClipDistance}; + main1(v_uv, a_uv, perVertexStruct, a_pos); + const auto _tmp = type10 {v_uv, perVertexStruct.gl_Position, perVertexStruct.gl_PointSize, perVertexStruct.gl_ClipDistance}; return main2Output { _tmp.member, _tmp.gl_Position1, _tmp.gl_PointSize1, {_tmp.gl_ClipDistance1.inner[0]} }; }