Error in compiling shader for iOS Metal

Would anyone know why I’d get an error when compiling a shader for metal? The shader works fine on gles 2.0, but for some reason generates an error with metal… Here is the code (you might recognize it if you saw my other thread) and the error below:

Anyone have any ideas about the issue? Thanks for any help!

Shader "Hidden/Glow 11/Blur GL" {
    Properties {
        _MainTex ("", 2D) = "" {}
    }
 
    CGINCLUDE
 
    #include "UnityCG.cginc"
   
    struct v2f {
        half4 pos : POSITION;
        half4 uv[5] : TEXCOORD0;
    };
 
    sampler2D _MainTex;
        half4 _MainTex_TexelSize;
      
    struct appdata_glow {
        half4 vertex : POSITION;
        half4 texcoord[5] : TEXCOORD;
    };
 
    v2f vert( appdata_glow v )
    {
        v2f o;
       float offX = _MainTex_TexelSize.x;
        float offY = _MainTex_TexelSize.y;
      
        o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
        o.uv[0] = v.texcoord[0] + float4(offX*.5f,offY*.5f,0,0);
        o.uv[1] = v.texcoord[1]+ float4(-offX*1.5f,-offY*1.5f,0,0);
        o.uv[2] = v.texcoord[2]+ float4(-offX,-offY,0,0);
        return o;
    }
 
    fixed4 frag(v2f pixelData) : COLOR
    {
        return tex2D(_MainTex, pixelData.uv[0]) * .2270270270f +
            (tex2D(_MainTex, pixelData.uv[1]) + tex2D(_MainTex, pixelData.uv[2])) * .3162162162f;
    }
 
    ENDCG
 
    Subshader {
        Pass {
          ZTest Always Cull Off ZWrite Off
          Fog { Mode off }
          ColorMask RGB
      
          CGPROGRAM
          #pragma glsl
          #pragma only_renderers gles opengl gles3 metal
          #pragma fragmentoption ARB_precision_hint_fastest
          #pragma vertex vert
          #pragma fragment frag
          ENDCG
        }
    }
   
    Fallback off

And the error:

Invalid unit for GL texcoord (got 4 but only 0…3 valid)
System.InternalEnumerator1:get_Current() UnityEngine.Graphics:Internal_BlitMultiTap(Texture, RenderTexture, Material, Vector2[ ]) UnityEngine.Graphics:BlitMultiTap(Texture, RenderTexture, Material, Vector2[ ]) Glow11.Blur.BlurBase:BlurBuffer(RenderTexture, RenderTexture) Glow11.Blur.DefaultBlur:BlurAndBlitBuffer(RenderTexture, RenderTexture, Settings, Boolean) Glow11.Blur.AdvancedBlur:BlurAndBlitBuffer(RenderTexture, RenderTexture, Settings, Boolean) Glow11.Glow11:OnRenderImage(RenderTexture, RenderTexture) System.InternalEnumerator1:get_Current()

[ line 1783]
(Filename: Line: 1783)

Metal: Error creating pipeline state: Vertex attribute 2 is not defined in the vertex layout.

Any chance that this is actually a bug in unity and not an bug in my code? :slight_smile: Just wondering because I know the metal pipeline was super recently integrated, not sure how air tight it is at the moment…

Honestly, I have no idea on Metal, but the error suggests you have too many texcoords defined. You have 5 defined, and in the code, it looks like only 3 are used anyways. Try reducing the numbers of them.

1 Like

only uv[0] - [2] are used in vert and frag, [3] and [4] are not used at all! Try to do this
half4 uv[3]: TEXCOORD0;
half4 texcoord[3]: TEXCOORD;

Thanks for the thought, I tried it, still didn’t work. And unfortunately I got the exact same error. Not sure what’s up with metal! I built for gles 3 and that actually ran as well! Not sure what the problem with metal is…

try to replace the uv array with individual variables? and try to used half2 instead of half4?