Search Unity

Property stripping on iOS Metal

Discussion in 'Shaders' started by sbsmith, Jan 20, 2020.

  1. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    126
    I'm bashing my head against my desk trying to figure out why, after packaging this shader in asset bundles, it's showing up in my Frame Debugger as not having the correct properties, culling settings, etc.

    Is there something here that is incompatible with Metal?

    (Note: the mesh being passed in, is already in view volume coordinates and the mesh has been tested and works in another metal application on device)

    Code (CSharp):
    1. Shader "AFoldApart/PaperProjection/PrepareScreenOverlayWithScaledGameBlit"
    2. {
    3.     // Command buffers write to global keywords so "white" will always take priority because it is more specific than the global
    4.     //Properties
    5.     //{
    6.     //    _MainTex ("Texture", 2D) = "white" {}
    7.     //}
    8.     SubShader
    9.     {
    10.         Tags{ "Queue" = "Geometry" "PreviewType" = "Plane" }
    11.  
    12.         CGINCLUDE
    13.         #pragma target 3.0
    14.         #include "UnityCG.cginc"
    15.  
    16.         struct appdata
    17.         {
    18.             float3 vertex : POSITION;
    19.             float2 uv : TEXCOORD0;
    20.         };
    21.  
    22.         struct v2f
    23.         {
    24.             float2 uv : TEXCOORD0;
    25.             float4 vertex : SV_POSITION;
    26.         };
    27.  
    28.         sampler2D _MainTex;
    29.  
    30.         v2f vert(appdata v)
    31.         {
    32.             v2f o;
    33.             o.vertex = float4(v.vertex, 1);
    34.             o.uv = v.uv;
    35. #ifndef UNITY_UV_STARTS_AT_TOP
    36.             o.uv.y = 1 - o.uv.y;
    37. #endif
    38.             return o;
    39.         }
    40.  
    41.         fixed4 frag(v2f i, out float out_depth : SV_Depth) : SV_Target
    42.         {
    43.             out_depth = Linear01Depth(1.0);
    44.             return tex2D(_MainTex, i.uv);
    45.         }
    46.         ENDCG
    47.  
    48.         Pass
    49.         {
    50.             ZWrite on
    51.             ZTest always
    52.             Cull back
    53.  
    54.             CGPROGRAM
    55.             #pragma vertex vert
    56.             #pragma fragment frag
    57.             ENDCG
    58.         }
    59.     }
    60. }
    61.  
    Notice that the parameters are wrong and the texture is missing. If I run without asset bundles, the texture shows up and things work as expected. On PC, Switch, XBox, and PS4, the same shader runs as expected with the same AssetBundle configuration.
    Screen Shot 2020-01-21 at 12.44.05 AM.png
     
    Last edited: Jan 21, 2020
  2. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    126
    I tested the shader in another project but without asset bundles and it ran on device. It seems that there is something about the asset bundle that's corrupting the shader. Again, this seems unusual because this asset bundle configuration runs fine on every console and PC.
     
  3. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    126
    I solved it! There was a two-fold solution.

    1. I added the shaders to the Always Include list (even though this was not required on Mac, PC, Switch, XBox, or PS4)
    2. I deleted ALL my asset bundles and rebuilt them. I had previously tried rebuilding only the bundles that contained the shaders, but apparently once you add something to the Always Include list, you need to rebuild all the bundles for iOS (according to another thread).

    Later, I will do a sanity check to make sure that step 1 was actually required and there wasn't just some weird corruption of my bundles. I think I had done a full rebuild to test, and it failed, but I am not certain. It was late and I was tired.