Unity 5.2 HLSL2GLSL compiler and optimiser issue

Since upgrading to 5.2 our Android shaders have started failing to compile on device.
Specifically the HLSL2GLSL compiler (or optimiser) is outputting bad code … see this (redacted).

mediump  vec4 phase0_Output0_1;
out mediump float vs_TEXCOORD1;
out mediump vec4 vs_COLOR0;
highp vec4 t0;
void main()
{
    t0 = in_POSITION0.yyyy * glstate_matrix_mvp[1];
    t0 = glstate_matrix_mvp[0] * in_POSITION0.xxxx + t0;
    t0 = glstate_matrix_mvp[2] * in_POSITION0.zzzz + t0;
    gl_Position = glstate_matrix_mvp[3] * in_POSITION0.wwww + t0;
    t0.xyz = in_POSITION0.yyy * glstate_matrix_modelview0[1].xyz;
    t0.xyz = glstate_matrix_modelview0[0].xyz * in_POSITION0.xxx + t0.xyz;
    t0.xyz = glstate_matrix_modelview0[2].xyz * in_POSITION0.zzz + t0.xyz;
    t0.xyz = glstate_matrix_modelview0[3].xyz * in_POSITION0.www + t0.xyz;
    t0.x = dot(t0.xyz, t0.xyz);
    t0.z = sqrt(t0.x);
    t0.xy = in_TEXCOORD0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
    phase0_Output0_1 = t0.xyz;
    vs_COLOR0 = in_COLOR0;
vs_TEXCOORD0 = phase0_Output0_1.xy;
vs_TEXCOORD1 = phase0_Output0_1.z;
    return;
}

t0 is some temporary vec4 generated by the cross compiler and phase0_Output0_1 is also a vec4 generated by the compiler - not one of ours.
It then attempts to do …

phase0_Output0_1 = t0.xyz;

Which results in the following runtime error on the devices we’ve tested so far …

09-09 18:37:19.976: D/Unity(32761): ERROR: 0:128: ‘assign’ : cannot convert from ‘3-component vector of float’ to ‘4-component vector of float’
09-09 18:37:19.976: D/Unity(32761): ERROR: 1 compilation errors. No code generated.
09-09 18:37:19.976: D/Unity(32761): Note: Creation of internal variant of shader (2-pass)’ failed.

Is anybody else seeing GLSL compile issues at runtime?

WIth which platform? if it’s GLES2… :rage: I ran into an odd issue where the stupid thing wouldn’t generate code at all! (This was due to using a float3x3 as an input) Lucky I found a workaround that didn’t need that… :smile:

I can take a look at your shader if you like, I am starting to develop an eye for silly things like this… Anyway, part of the issue I think is the fact that the OpenGL shading pipeline had a complete overhaul in 5.1, and as always, things are bound to break somewhere.

Just to clarify, it was an issue regarding half → float conversion. I had some semantic types as half in my v2f structure, for which the compiler was generating

phase0_Output0_1 = t0.xyz;

when I changed that type to float, it worked fine.

Really? :hushed: Damn, that’s harsh… :confused: