Search Unity

iOS Metal Compilation Failed

Discussion in 'Shaders' started by kromenak, Jul 20, 2016.

  1. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    I have a shader that works on both OpenGLES2 and OpenGLES3. However, when I try to run it using Metal, I get the following error:

    Unexpected type name 'half2': expected expression

    This is shader code generated by Unity from the shader lab file. Here's the bit that Metal is unhappy about:
    Code (CSharp):
    1. float2 tmpvar_54[4];
    2. tmpvar_54[0] = tmpvar_32;
    3. tmpvar_54[1] = tmpvar_38;
    4. tmpvar_54[2] = tmpvar_44;
    5. tmpvar_54[3] = (tmpvar_53 / float2(1024.0, 1024.0));
    6. half2 tmpvar_55[4];
    7. tmpvar_55 = half2[4](tmpvar_54); // <-- ERROR!
    I'm a beginner with Metal, so I'm unclear what the error is referring to. It seems to create an array of 4 half2 values, and then assign to it from an array of 4 float2. Seems like a reasonable thing to do?

    This isn't a unity-specific error or anything. If I paste the code into a .metal file in Xcode, it also fails to compile, so the metal compiler just doesn't like whatever is happening on that line! Any ideas why that is?
     
  2. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Not sure if shader arrays work differently to normal programming arrays but you have created an array with 4 entries but then try to accept the 5th entry. I could be talking bollocks because I no nothing about shader coding but arrays normally count from zero so where you have half2[4] is actually the 5th entry in the array.
     
  3. kromenak

    kromenak

    Joined:
    Feb 9, 2011
    Posts:
    270
    Hi, thanks for the reply! From my perspective, it appears that it's trying to cast a float2 array of four elements to a half2 array of four elements. Upon further investigation, it appears that Metal's language is based on C++, but I'm unfortunately a bit rusty on that front too! The error doesn't give much hint to the problem either.

    I was hoping to get some feedback from someone on Unity's end, since it seems that their shader code generator from shaderlab is generating an error in this case...